<?php
namespace Home\Controller;
use Think\Controller;
use Think\Page;
use Think\Upload;
class IndexController extends CommunalController{
	//首页 designed by:zhangsen 2017-04-24
	function index(){
		//公告
		$db_notice=M('db_notice');
		if(get_permission('GG',1)){
		}elseif(get_permission('GG',3)){
			$where['_string']="find_in_set('".$this->login_id."',uids) or (is_all=1) or add_uid='".$this->login_id."'";
		}else{
			$where['_string']="find_in_set('".$this->login_id."',uids) or (is_all=1)";
		}
		$notice_list=$db_notice->where($where)->order('add_date desc')->limit(5)->select();
		$db_notice_reply=M('db_notice_reply');
		//第一条数据
		$first_result=$db_notice->where($where)->order('add_date desc')->find();
		foreach($notice_list as $key=>$value)
		{
			if($first_result['id']==$value['id']){
				$notice_list[$key]['first']=1;
			}
			$notice_list[$key]['add_user']=$this->get_username($value['add_uid']);
			//评论数量
			$where_ask['main_id']=$value['id'];
			$where_ask['reply_id']=0;
			$notice_list[$key]['ask_count']=$db_notice_reply->where($where_ask)->count();
			//回复数量
			$where_ask['reply_id']=array('neq',0);
			$notice_list[$key]['answer_count']=$db_notice_reply->where($where_ask)->count();
		}
		$this->assign('notice_list',$notice_list);
		//我参与的项目
		$db_project=M('db_project');
		$string=NULL;
		if($this->get_is_project()){
			$string.="(manager_uid=".$this->login_id.") or (director_uid=".$this->login_id.") or";
		}
		if($this->get_is_project_function()){
			$db_project_function=M('db_project_function'); 
			$where_f['uid']=$this->login_id;
			$where_f['start_date']=array('elt',date("Y-m-d"));
			$where_f['end_date']=array('egt',date("Y-m-d"));
			$result_f=$db_project_function->where($where_f)->select();
			foreach($result_f as $key=>$value){
				$pids.=$value['pid'].',';
			}
			$string.="(db_project.id in (".rtrim($pids,',').")) or";
		}
		if($this->get_is_project_user()){
			$string.='(find_in_set("'.$this->login_id.'",project_uids)) or';
			$t_day=date('Y-m-d');
			$str="(SELECT db_project.id,db_project.project_num,db_project.project_name,db_project.status,db_project_user.pid,db_project_user.uid,db_project_user.nature,db_project_user.come_date FROM `db_project` inner join db_project_user on db_project.id=db_project_user.pid LEFT JOIN db_user on db_project_user.uid=db_user.id WHERE ( db_project.`center_id` = 130005 ) AND (('".$t_day."'>=come_date and '".$t_day."'<`out_date`) or ('".$t_day."'>=come_date and out_date is NULL)) and db_user.is_project=1 and db_user.status=1 and db_project_user.uid='".$this->login_id."' group by pid) ORDER BY project_num desc,come_date desc";
			$Model=M();
			$result_s=$Model->query($str);
			if($result_s){
				foreach($result_s as $key=>$value){
					$yy_pids.=$value['id'].',';
				}
				$string.="(db_project.id in (".rtrim($yy_pids,',').")) or";
			}
		}
		if($string){
			$where_m['_string']=rtrim($string,'or');
			$my_project=$db_project->field('db_project.*')->join('left join db_project_bg on db_project.id=db_project_bg.pid')->where($where_m)->order('db_project.add_date desc')->limit(5)->select();
		}
		$this->assign('my_project',$my_project);
		//收藏夹
		$db_library_reading=M('db_library_reading');
		$where_c['collection']=2;
		$where_c['db_library_reading.add_uid']=$this->login_id;
		$collection=$db_library_reading->field('db_library_main.*')->where($where_c)->join( 'LEFT JOIN db_library_main ON db_library_reading.mid=db_library_main.id')->limit(5)->order('db_library_reading.id desc')->select();
		foreach($collection as $kc=>$vc){
			if($vc['type']==5){
				$collection[$kc]['name']=$this->get_username($vc['name']);
			}
			$type_name=$this->get_db_universal_type(5,1,NULL,NULL,$vc['type']);
			$collection[$kc]['type_name']=$type_name['name2'];
			$collection[$kc]['classif']=$type_name['name4'];
			preg_match_all("/./us",$vc['name'],$matchs);
			$collection[$kc]['name_str']=count($matchs[0]);
		}
		$this->assign('collection',$collection);
		//搜库推荐
		$arr=$this->get_db_universal_type(10,NULL,NULL,NULL,NULL,1);
		foreach($arr as $ka=>$va){
			$array[]=$va['name1'];
		}
		$array=join(',',$array);
		$db_library_main=M('db_library_main');
		$where_z['home']=1;
		$top=$db_library_main->where($where_z)->order('zd_date desc')->limit(5)->select();
		foreach($top as $kt=>$vt){
			if($vt['type']==5){
				$top[$kt]['name']=$this->get_username($vt['name']);
			}
			$type_name=$this->get_db_universal_type(5,1,NULL,NULL,$vt['type']);
			$top[$kt]['type_name']=$type_name['name2'];
			$top[$kt]['classif']=$type_name['name4'];
			preg_match_all("/./us",$vt['name'],$match);
			$top[$kt]['name_str']=count($match[0]);
		}
		$this->assign('top',$top);
		//滚动消息
		$arrs=$this->get_db_universal_type(10,NULL,NULL,NULL,NULL,NULL,1);
		foreach($arrs as $ks=>$vs){
			$arrays[]=$vs['name1'];
		}
		$arrays=join(',',$arrays);
		$db_library_share=M('db_library_share');
		$where_sh['suid']=$this->login_id;
		$where_sh['rstatus']=-1;
		$share=$db_library_share->field('db_library_share.*')->where($where_sh)->join('LEFT JOIN db_library_share_starus ON db_library_share.id=db_library_share_starus.sid')->order('share_date desc')->group('db_library_share.id')->select();
		foreach($share as $ks=>$vs){
			$type_name=$this->get_db_universal_type(5,1,NULL,NULL,$vs['folder_type']);
			$share[$ks]['type_name']=$type_name['name2'];
			$share[$ks]['classif']=$type_name['name4'];
			if(empty($vs['folder_name'])){
				$where_n['id']=$vs['mid'];
				$share_n=$db_library_main->where($where_n)->find();
				if($share_n['type']==5){
					$share[$ks]['name']=$this->get_username($share_n['name']);
				}else{
					$share[$ks]['name']=$share_n['name'];
				}
			}
		}
		$this->assign('share',$share);
		//消息数量
		$db_alert=M('db_alert');
		$where_al['to_uid']=$this->login_id;
		$where_al['status']=-1;
		$alert=$db_alert->where($where_al)->order('add_date desc')->select();
		if((count($share)+count($alert))>99){$count='99+';}else{$count=count($share)+count($alert);}
		$this->assign('alert',$alert);
		$this->assign('count',$count);
		$this->display();
	}

	//搜库更多 designed by:zhaoshihao 2017-11-28
	function index_more(){
		if($_REQUEST['action']=='collection'){
			//收藏夹
			$db_library_reading=M('db_library_reading');
			$where_c['collection']=2;
			$where_c['db_library_reading.add_uid']=$this->login_id;
			$collection=$db_library_reading->field('db_library_main.*')->where($where_c)->join( 'LEFT JOIN db_library_main ON db_library_reading.mid=db_library_main.id')->order('db_library_reading.id desc')->select();
			foreach($collection as $kc=>$vc){
				$type_name=$this->get_db_universal_type(5,1,NULL,NULL,$vc['type']);
				$collection[$kc]['type_name']=$type_name['name2'];
				$collection[$kc]['classif']=$type_name['name4'];
				if($vc['type']==5){
					$collection[$kc]['name']=$this->get_username($vc['name']);
				}
			}
			$this->assign('result',$collection);
			$this->assign('con','收藏夹');
		}elseif($_REQUEST['action']=='top'){
			//置顶推荐
			$arr=$this->get_db_universal_type(10,NULL,NULL,NULL,NULL,1);
			foreach($arr as $ka=>$va){
				$array[]=$va['name1'];
			}
			$array=join(',',$array);
			$db_library_main=M('db_library_main');
			$where_z['home']=1;
			$top=$db_library_main->where($where_z)->order('zd_date desc')->select();
			foreach($top as $kt=>$vt){
				if($vt['type']==5){
					$top[$kt]['name']=$this->get_username($vt['name']);
				}
				$type_name=$this->get_db_universal_type(5,1,NULL,NULL,$vt['type']);
				$top[$kt]['type_name']=$type_name['name2'];
				$top[$kt]['classif']=$type_name['name4'];
			}
			$this->assign('result',$top);
			$this->assign('con','搜库推荐');
		}elseif($_REQUEST['action']=='share'){
			if($_REQUEST['typ']==1){
				//分享文件
				$db_library_share=M('db_library_share');
				$db_library_main=M('db_library_main');
				$db_library_share_starus=M('db_library_share_starus');
				$where['add_uid']=$this->login_id;
				$share=$db_library_share->where($where)->order('folder_name,share_date desc')->select();
				foreach($share as $ks=>$vs){
					$type_name=$this->get_db_universal_type(5,1,NULL,NULL,$vs['folder_type']);
					$share[$ks]['type_name']=$type_name['name2'];
					$share[$ks]['classif']=$type_name['name4'];
					$share[$ks]['add_user']=$this->get_username($vs['add_uid']);
					if(empty($vs['folder_name'])){
						$where_n['id']=$vs['mid'];
						$share_n=$db_library_main->where($where_n)->find();
						if($share_n['type']==5){
							$share[$ks]['name']=$this->get_username($share_n['name']);
						}else{
							$share[$ks]['name']=$share_n['name'];
						}
					}else{
						$where_m['id']=array('in',$vs['mid']);
						$share[$ks]['detail']=$db_library_main->where($where_m)->select();
						foreach($share[$ks]['detail'] as $ka=>$va){
							if($va['type']==5){
								$share[$ks]['detail'][$ka]['name']=$this->get_username($va['name']);
							}
							$share[$ks]['detail'][$ka]['classif']=$type_name['name4'];
						}
					}
					$where_st['sid']=$vs['id'];
					$asd=$db_library_share_starus->where($where_st)->find();
					if(empty($asd)){unset($share[$ks]);}
				}
				$share=array_values($share);
				$this->assign('con','消息');
				$this->assign('result',$share);
				$this->assign('typ',$_REQUEST['typ']);
				$this->assign('rstatus',-1);
			}else{
				if(!empty($_REQUEST['rstatus'])){$rstatus=$_REQUEST['rstatus'];}else{$rstatus=-1;}
				$this->assign('rstatus',$rstatus);
				//被分享文件
				$db_library_main=M('db_library_main');
				$db_library_share_starus=M('db_library_share_starus');
				$arrs=$this->get_db_universal_type(10,NULL,NULL,NULL,NULL,NULL,1);
				foreach($arrs as $ks=>$vs){
					$arrays[]=$vs['name1'];
				}
				$arrays=join(',',$arrays);
				$db_library_share=M('db_library_share');
				$where_sh['suid']=$this->login_id;
				if($rstatus==1){
					$where_sh['rstatus']=1;
					$sid=$db_library_share->field('db_library_share.*')->where($where_sh)->join('LEFT JOIN db_library_share_starus ON db_library_share.id=db_library_share_starus.sid')->order('share_date desc')->group('db_library_share.id')->select();
					foreach($sid as $kss=>$vss){
						$where_a['sid']=$vss['id'];
						$where_a['suid']=$this->login_id;
						$has=$db_library_share_starus->where($where_a)->select();
						foreach($has as $kb=>$vb){
							if($vb['rstatus']==-1){$have[]=$vb['sid'];}
						}
					}
					$where_sh['db_library_share.id']=array('not in',$have);
				}elseif($rstatus==-1){
					$where_sh['rstatus']=-1;
				}
				if(!empty($_REQUEST['id'])){
					unset($where_sh);
					$where_sh['db_library_share.id']=$_REQUEST['id'];
				}
				$share=$db_library_share->field('db_library_share.*')->where($where_sh)->join('LEFT JOIN db_library_share_starus ON db_library_share.id=db_library_share_starus.sid')->order('share_date desc')->group('db_library_share.id')->select();
				foreach($share as $ks=>$vs){
					$type_name=$this->get_db_universal_type(5,1,NULL,NULL,$vs['folder_type']);
					$share[$ks]['type_name']=$type_name['name2'];
					$share[$ks]['classif']=$type_name['name4'];
					$share[$ks]['add_user']=$this->get_username($vs['add_uid']);
					if(empty($vs['folder_name'])){
						$where_n['id']=$vs['mid'];
						$share_n=$db_library_main->where($where_n)->find();
						if($share_n['type']==5){
							$share[$ks]['name']=$this->get_username($share_n['name']);
						}else{
							$share[$ks]['name']=$share_n['name'];
						}
						$where['sid']=$vs['id'];
						$where['suid']=$this->login_id;
						$read=$db_library_share_starus->where($where)->find();
						if($read['rstatus']==1){$share[$ks]['rsta']=1;}
					}else{
						$where_m['id']=array('in',$vs['mid']);
						$share[$ks]['detail']=$db_library_main->where($where_m)->select();
						foreach($share[$ks]['detail'] as $ka=>$va){
							$where_f['sid']=$vs['id'];
							$where_f['mid']=$va['id'];
							$where_f['suid']=$this->login_id;
							$read=$db_library_share_starus->where($where_f)->find();
							
							if($read['rstatus']==1){$share[$ks]['detail'][$ka]['rsta']=1;}
							if($va['type']==5){
								$share[$ks]['detail'][$ka]['name']=$this->get_username($va['name']);
							}
							$share[$ks]['detail'][$ka]['classif']=$type_name['name4'];
						}
						//是否已读
						$where_ss['sid']=$vs['id'];
						$where_ss['suid']=$this->login_id;
						$read=$db_library_share_starus->where($where_ss)->select();
						$sum=count($read);
						foreach($read as $k1=>$v1){
							if($v1['rstatus']==1){$sum--;}
						}
						if($sum==0){$share[$ks]['rsta']=1;}
					}
				}
				$share=$this->multi_array_sort($share,'rsta',SORT_ASC);
				$this->assign('con','消息');
				$this->assign('result',$share);
				$this->assign('typ',$_REQUEST['typ']);
				$this->assign('id',$_REQUEST['id']);
			}
		}
		//未读提醒数量
		$al_ct=$this->get_alert_num();
		$this->assign('al_ct',$al_ct['al_ct']?$al_ct['al_ct']:NULL);
		$this->assign('action',$_REQUEST['action']);
		$this->display();
	}
	
	//审核流程管理 designed by:zhangsen 2017-12-12
	function audit_list(){
		//parent::check_permission('LC');
		//查找
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		$db_audit_main=M('db_audit_main');
		if(!empty($keyword))
		{
			$map['db_project.project_num']=array('like','%'.$keyword.'%');
			$map['db_project.project_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where_p['_complex']=$map;
		}
		//审核状态
		if(!empty($_REQUEST['state'])){$state=$_REQUEST['state'];}else{$state=-10;}
		$this->assign('state',$state);
		//我的流程
		if(!empty($_REQUEST['type'])){$type=$_REQUEST['type'];}else{$type=-10;}
		$this->assign('type',$type);
		//分类筛选
		if(!empty($_REQUEST['sh_type'])){$sh_type=$_REQUEST['sh_type'];}else{$sh_type=-10;}
		$this->assign('sh_type',$sh_type);
		//无项目经理
		$db_relationship=M('db_relationship');
		$where_r['leader_uid']=$this->login_id;
		$result_r=$db_relationship->where($where_r)->find();
		if($result_r){
			$person_uid=$result_r['person_uid'];
		}else{
			$person_uid='NULL';
		}
		$Model=M();
		if($state==1)
		{
			if($sh_type==1){
				$str='(SELECT db_audit_main.* FROM `db_audit_main` Left Join db_project on db_project.id=db_audit_main.pid LEFT JOIN db_universal_audit ON db_audit_main.audit_type=db_universal_audit.audit_type WHERE ( ((db_project.manager_uid="'.$this->login_id.'") and (((audit1_uid="'.$this->login_id.'") and ((db_audit_main.status=2) or (db_audit_main.status=3))) or (db_audit_main.status=1))) or ( (find_in_set("'.$this->login_id.'",audit_uid)) and (((audit2_uid="'.$this->login_id.'") and ((db_audit_main.status=3))) or (db_audit_main.status=2))) ) and (db_audit_main.type=1) GROUP BY db_audit_main.id) ORDER BY id desc';
			}
			elseif($sh_type==3){
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=3 and db_universal_audit.audit_type=130005 WHERE db_audit_main.type=3 and (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) ORDER BY id desc';
			}
			elseif($sh_type==4){
				$str='(SELECT db_audit_main.* FROM `db_audit_main` Left Join db_project on db_project.id=db_audit_main.pid LEFT JOIN db_universal_audit ON db_audit_main.audit_type=db_universal_audit.audit_type WHERE ( ( ((((db_project.manager_uid="'.$this->login_id.'") and (db_audit_main.status=1) or (db_audit_main.status=2)) or (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status=2)) and (db_audit_main.type=4)) ) ) GROUP BY db_audit_main.id) ORDER BY id desc';
			}
			elseif($sh_type==5){
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=5 and db_audit_main.audit_type=db_universal_audit.audit_type WHERE db_audit_main.type=5 and (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) ORDER BY id desc';
			}
			elseif($sh_type==6){
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=6 WHERE db_audit_main.type=6 and (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) ORDER BY id desc';
			}
			elseif($sh_type==7){
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=7 WHERE db_audit_main.type=7 and ((find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>1) or (db_audit_main.status=1 and add_uid in('.$person_uid.'))) ORDER BY id desc';
			}else{
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=3 and db_universal_audit.audit_type=130005 WHERE db_audit_main.type=3 and (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) UNION ALL SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=5 and db_audit_main.audit_type=db_universal_audit.audit_type WHERE db_audit_main.type=5 and (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) UNION ALL (SELECT db_audit_main.* FROM `db_audit_main` Left Join db_project on db_project.id=db_audit_main.pid LEFT JOIN db_universal_audit ON db_audit_main.audit_type=db_universal_audit.audit_type WHERE ((((db_project.manager_uid="'.$this->login_id.'") and (db_audit_main.status=1) or (db_audit_main.status=2)) or (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status=2)) and (db_audit_main.type=4))  GROUP BY db_audit_main.id) UNION ALL (SELECT db_audit_main.* FROM `db_audit_main` Left Join db_project on db_project.id=db_audit_main.pid LEFT JOIN db_universal_audit ON db_audit_main.audit_type=db_universal_audit.audit_type WHERE ( ((db_project.manager_uid="'.$this->login_id.'") and (((audit1_uid="'.$this->login_id.'") and ((db_audit_main.status=2) or (db_audit_main.status=3))) or (db_audit_main.status=1))) or ( (find_in_set("'.$this->login_id.'",audit_uid)) and (((audit2_uid="'.$this->login_id.'") and ((db_audit_main.status=3))) or (db_audit_main.status=2))) ) and (db_audit_main.type=1) GROUP BY db_audit_main.id) UNION ALL SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=6 WHERE db_audit_main.type=6 and (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) UNION ALL SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=7 WHERE db_audit_main.type=7 and ((find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>1) or (db_audit_main.status=1 and add_uid in('.$person_uid.'))) ORDER BY id desc';	
			}
			$result=$Model->query($str);
		}
		elseif($state==2){
			if($sh_type==1){
				$where_p['_string']='(audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") and ((status=4) and (db_audit_main.type=1))';
			}
			elseif($sh_type==3){
				$where_p['_string']='(audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") and ((status=3) and (db_audit_main.type=3))';
			}
			elseif($sh_type==4){
				$where_p['_string']='(audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") and ((status=3) and (db_audit_main.type=4))';
			}
			elseif($sh_type==5){
				$where_p['_string']='(audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") and ((status=3) and (db_audit_main.type=5))';
			}
			elseif($sh_type==6){
				$where_p['_string']='(audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") and ((status=2) and (db_audit_main.type=6))';
			}
			elseif($sh_type==7){
				$where_p['_string']='(audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'" or audit3_uid="'.$this->login_id.'" or audit4_uid="'.$this->login_id.'" or audit5_uid="'.$this->login_id.'") and ((status=6) and (db_audit_main.type=7))';
			}else{
				$where_p['_string']='(audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'" or audit3_uid="'.$this->login_id.'" or audit4_uid="'.$this->login_id.'" or audit5_uid="'.$this->login_id.'") and (((status=3) and (db_audit_main.type=3 or db_audit_main.type=5 or db_audit_main.type=4)) or ((status=4) and (db_audit_main.type=1)) or ((status=2) and (db_audit_main.type=6)) or ((status=6) and (db_audit_main.type=7)))';	
			}
			$result=$db_audit_main->where($where_p)->order('db_audit_main.id desc')->select();
		}else{
			if($sh_type==1){
				$str='(SELECT db_audit_main.* FROM `db_audit_main` Left Join db_project on db_project.id=db_audit_main.pid LEFT JOIN db_universal_audit ON db_audit_main.audit_type=db_universal_audit.audit_type WHERE (((db_project.manager_uid="'.$this->login_id.'") and ((db_audit_main.status=1) or (db_audit_main.status=2))) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") or (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status=2)) and (db_audit_main.type=1)  GROUP BY db_audit_main.id) ORDER BY id desc';
			}
			elseif($sh_type==3){
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=3 and db_universal_audit.audit_type=130005 WHERE db_audit_main.type=3 and ( (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") ) ORDER BY id desc';
			}
			elseif($sh_type==4){
				$str='(SELECT db_audit_main.* FROM `db_audit_main` Left Join db_project on db_project.id=db_audit_main.pid LEFT JOIN db_universal_audit ON db_audit_main.audit_type=db_universal_audit.audit_type WHERE (((db_project.manager_uid="'.$this->login_id.'") and ((db_audit_main.status=1) or (db_audit_main.status=2))) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") or (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status=2)) and (db_audit_main.type=4) GROUP BY db_audit_main.id) ORDER BY id desc';
			}
			elseif($sh_type==5){
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=5 and db_audit_main.audit_type=db_universal_audit.audit_type WHERE db_audit_main.type=5 and ((find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'")) ORDER BY id desc';
			}
			elseif($sh_type==6){
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=6 WHERE db_audit_main.type=6 and ((find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) or (audit1_uid="'.$this->login_id.'")) ORDER BY id desc';
			}
			elseif($sh_type==7){
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=7 WHERE db_audit_main.type=7 and ((((find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>1) or (db_audit_main.status=1 and add_uid in('.$person_uid.')))) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'" or audit3_uid="'.$this->login_id.'" or audit4_uid="'.$this->login_id.'" or audit5_uid="'.$this->login_id.'")) ORDER BY id desc';
			}else{
				$str='SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=3 and db_universal_audit.audit_type=130005 WHERE db_audit_main.type=3 and ( (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") ) UNION ALL SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=5 and db_audit_main.audit_type=db_universal_audit.audit_type WHERE db_audit_main.type=5 and ( (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") ) UNION ALL (SELECT db_audit_main.* FROM `db_audit_main` Left Join db_project on db_project.id=db_audit_main.pid LEFT JOIN db_universal_audit ON db_audit_main.audit_type=db_universal_audit.audit_type WHERE  (((db_project.manager_uid="'.$this->login_id.'") and ((db_audit_main.status=1) or (db_audit_main.status=2))) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") or (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status=2)) and (db_audit_main.type=4) GROUP BY db_audit_main.id) UNION ALL (SELECT db_audit_main.* FROM `db_audit_main` Left Join db_project on db_project.id=db_audit_main.pid LEFT JOIN db_universal_audit ON db_audit_main.audit_type=db_universal_audit.audit_type WHERE (((db_project.manager_uid="'.$this->login_id.'") and ((db_audit_main.status=1) or (db_audit_main.status=2))) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'") or (find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status=2)) and (db_audit_main.type=1)  GROUP BY db_audit_main.id) UNION ALL SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=6 WHERE db_audit_main.type=6 and ((find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>0) or (audit1_uid="'.$this->login_id.'")) UNION ALL SELECT db_audit_main.* FROM `db_audit_main` LEFT JOIN db_universal_audit ON db_audit_main.status=db_universal_audit.audit_sort and db_universal_audit.type=7 WHERE db_audit_main.type=7 and (((find_in_set("'.$this->login_id.'",audit_uid) and db_audit_main.status>1) or (db_audit_main.status=1 and add_uid in('.$person_uid.'))) or (audit1_uid="'.$this->login_id.'" or audit2_uid="'.$this->login_id.'" or audit3_uid="'.$this->login_id.'" or audit4_uid="'.$this->login_id.'" or audit5_uid="'.$this->login_id.'") ) ORDER BY id desc';	
			}
			$result=$Model->query($str);
		}
		if(get_permission('LC',1))
		{
			unset($where_p);
			if($state==1){
				if($sh_type==1){
					$where_p['_string']='((status=1 or status=2 or status=3) and (db_audit_main.type=1))';
				}
				elseif($sh_type==3){
					$where_p['_string']='((status=1 or status=2) and (db_audit_main.type=3))';
				}
				elseif($sh_type==4){
					$where_p['_string']='((status=1 or status=2) and (db_audit_main.type=4))';
				}
				elseif($sh_type==5){
					$where_p['_string']='((status=1 or status=2) and (db_audit_main.type=5))';
				}
				elseif($sh_type==6){
					$where_p['_string']='((status=1) and (db_audit_main.type=6))';
				}
				elseif($sh_type==7){
					$where_p['_string']='((status=1 or status=2 or status=3 or status=4 or status=5) and (db_audit_main.type=7))';
				}else{
					$where_p['_string']="((status=1 or status=2) and (db_audit_main.type=3 or db_audit_main.type=5 or db_audit_main.type=4)) or ((status=1 or status=2 or status=3) and (db_audit_main.type=1)) or ((status=1) and (db_audit_main.type=6)) or ((status=1 or status=2 or status=3 or status=4 or status=5) and (db_audit_main.type=7))";	
				}
			}elseif($state==2){
				if($sh_type==1){
					$where_p['_string']='((status=4) and (db_audit_main.type=1))';
				}
				elseif($sh_type==3){
					$where_p['_string']='((status=3) and (db_audit_main.type=3))';
				}
				elseif($sh_type==4){
					$where_p['_string']='((status=3) and (db_audit_main.type=4))';
				}
				elseif($sh_type==5){
					$where_p['_string']='((status=3) and (db_audit_main.type=5))';
				}
				elseif($sh_type==6){
					$where_p['_string']='((status=2) and (db_audit_main.type=6))';
				}
				elseif($sh_type==7){
					$where_p['_string']='((status=6) and (db_audit_main.type=7))';
				}else{
					$where_p['_string']="((status=3) and (db_audit_main.type=3 or db_audit_main.type=5 or db_audit_main.type=4)) or ((status=4) and (db_audit_main.type=1)) or ((status=2) and (db_audit_main.type=6)) or ((status=6) and (db_audit_main.type=7))";	
				}
			}else{
				$where_p['db_audit_main.status']=array('in','1,2,3,4,5,6');
				if($sh_type==1){
					$where_p['db_audit_main.type']=1;
				}
				elseif($sh_type==3){
					$where_p['db_audit_main.type']=3;
				}
				elseif($sh_type==4){
					$where_p['db_audit_main.type']=4;
				}
				elseif($sh_type==5){
					$where_p['db_audit_main.type']=5;
				}
				elseif($sh_type==6){
					$where_p['db_audit_main.type']=6;
				}
				elseif($sh_type==7){
					$where_p['db_audit_main.type']=7;
				}else{
					$where_p['db_audit_main.status']=array('in','1,2,3,4,5,6');	
				}
			}
			$result=$db_audit_main->where($where_p)->order('db_audit_main.id desc')->select();
		}
		foreach($result as $k=>$v)
		{
			if($v['type']==4 or $v['type']==1){
				if($v['status']==1){
					$pro=$this->get_project($v['pid']);
					$result[$k]['audit_user']=$pro['manager_name'];
					$result[$k]['audit_uid']=$pro['manager_uid'];
					$result[$k]['add_user']=$this->get_username($v['add_uid']);
				}else{
					$audit_user=$this->audit_type_next($v['type'],$v['audit_type'],$v['status']);
					$result[$k]['audit_user']=$audit_user['audit_user'];
					$result[$k]['audit_uid']=$audit_user['audit_uid'];
					$result[$k]['add_user']=$this->get_username($v['add_uid']);
				}
				if($v['type']==1){
					if($v['status']==4){$result[$k]['status_name']='已完结';}else{$result[$k]['status_name']='进行中';}
					if($v['status']==3){$result[$k]['audit_user']=$this->get_username($v['add_uid']);}
				}else{
					if($v['status']==3){$result[$k]['status_name']='已完结';}else{$result[$k]['status_name']='进行中';}
				}
			}elseif($v['type']==6){
				//类别表
				$db_library_main=M('db_library_main');
				$where_t['id']=$v['audit_id'];
				$detail_sk=$db_library_main->where($where_t)->find();
				if($detail_sk['type']==2){
					$result[$k]['classif']=4;
					$result[$k]['dtype']=2;
				}elseif($detail_sk['type']==1){
					$result[$k]['classif']=1;
					$result[$k]['dtype']=1;
				}
				$audit_user=$this->audit_type_next($v['type'],NULL,$v['status']);
				$result[$k]['audit_user']=$audit_user['audit_user'];
				$result[$k]['audit_uid']=$audit_user['audit_uid'];
				$result[$k]['add_user']=$this->get_username($v['add_uid']);
				if($v['status']==2){$result[$k]['status_name']='已完结';}else{$result[$k]['status_name']='进行中';}
			}elseif($v['type']==7){
				$db_relationship=M('db_relationship');
				$where_rs['_string']="find_in_set('".$v['add_uid']."',person_uid)";
				$result_rs=$db_relationship->where($where_rs)->find();
				if($v['status']==1){
					$result[$k]['audit_user']=$result_rs['leader_name'];
					$result[$k]['audit_uid']=$result_rs['leader_uid'];
					$result[$k]['add_user']=$this->get_username($v['add_uid']);
				}else{
					$audit_user=$this->audit_type_next($v['type'],$v['audit_type'],$v['status']);
					$result[$k]['audit_user']=$audit_user['audit_user'];
					$result[$k]['audit_uid']=$audit_user['audit_uid'];
					$result[$k]['add_user']=$this->get_username($v['add_uid']);
				}
				if($v['status']==6){$result[$k]['status_name']='已完结';}else{$result[$k]['status_name']='进行中';}
			}else{
				$audit_user=$this->audit_type_next($v['type'],$v['audit_type'],$v['status']);
				$result[$k]['audit_user']=$audit_user['audit_user'];
				$result[$k]['audit_uid']=$audit_user['audit_uid'];
				$result[$k]['add_user']=$this->get_username($v['add_uid']);
				if($v['status']==3){$result[$k]['status_name']='已完结';}else{$result[$k]['status_name']='进行中';}
			}
			if($type==1){
				$audit_arr=explode(',',$result[$k]['audit_uid']);
				if(!in_array($this->login_id,$audit_arr)){
					unset($result[$k]);
				}
			}elseif($type==2){
				if($result[$k]['audit1_uid']!=$this->login_id && $result[$k]['audit2_uid']!=$this->login_id && $result[$k]['audit3_uid']!=$this->login_id && $result[$k]['audit4_uid']!=$this->login_id && $result[$k]['audit5_uid']!=$this->login_id){
					unset($result[$k]);
				}
			}
		}
		//数组分页
		import("ORG.Util.Page");
		$count=count($result);
		$Page=new  \Think\Page($count,C('PAGE_LIST_ROWS'),$parms);
		$result=array_slice($result, $Page->firstRow,$Page->listRows);
		$show=$Page->show();
		$this->assign('result',$result);
		$this->assign('page',$show);
		$this->display();
	}
	
	
	//审核流程管理-->操作 designed by:zhangsen 2017-12-12
	function audit_list_ajax(){
		$db_audit_main=M('db_audit_main');
		$status=$_REQUEST['status'];
		$up_where['id']=$_REQUEST['mid'];
		$find_result=$db_audit_main->where($up_where)->find();
		$user_find=$this->get_user($find_result['add_uid']);
		$find_result['add_user']=$user_find['username'];
		$project=$this->get_project($find_result['pid']);
		if($_REQUEST['type']){$type=$_REQUEST['type'];}else{$type=3;}
		if(!empty($_REQUEST['uuid'])){
			$sta=$this->audit_type_next_person($type,$find_result['audit_type'],$status,'egt');
			if($find_result['flow_status']==-1){
				if($find_result['status']==$find_result['arrive_status']){
					$status=$find_result['dh_status'];
					$sta=$this->audit_type_next_person($type,$find_result['audit_type'],$status,'egt');
				}
			}
		}elseif(empty($_REQUEST['uuid'])){
			if($type==7){
				$relationship=$this->user_list_ajax_relationship(1,$find_result['add_uid']);
				if(($relationship['audit_uid']==$this->login_id) and ($find_result['status']==2)){
					$status=1;
					$sta['audit_sort']=1;
				}else{
					if($status!=-1){
						$sta=$this->audit_type_next_person($type,$find_result['audit_type'],$status,'lt');
						$status=$sta['audit_sort'];
					}
				}
			}else{
				if($status!=-1){
					$sta=$this->audit_type_next_person($type,$find_result['audit_type'],$status,'lt');
					$status=$sta['audit_sort'];
				}
			}
		}
		switch($status){
			case -1:
				if(!empty($_REQUEST['flow_status'])){
					if($_REQUEST['flow_status']==-1){
						$up_where=$this->audit_status_judge($_REQUEST['arrive_status']);
					}else{
						$up_where=$this->audit_status_judge_all($_REQUEST['arrive_status'],$_REQUEST['dh_status']);
					}
					$up_where['status']=$_REQUEST['arrive_status'];
					$up_where['id']=$_REQUEST['mid'];
				}else{
					$up_where['status']=-1;
					$up_where['post_uid']=NULL;$up_where['post_date']=NULL;
					$up_where['audit1_uid']=NULL;$up_where['audit1_date']=NULL;$up_where['audit1_message']=NULL;
					$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
					$up_where['audit3_uid']=NULL;$up_where['audit3_date']=NULL;$up_where['audit3_message']=NULL;
					$up_where['audit4_uid']=NULL;$up_where['audit4_date']=NULL;$up_where['audit4_message']=NULL;
					$up_where['audit5_uid']=NULL;$up_where['audit5_date']=NULL;$up_where['audit5_message']=NULL;
				}
				if(!empty($_REQUEST['dh_message']))
				{
					$up_where['dh_uid']=$this->login_id;
					$up_where['dh_date']=date('Y-m-d H:i:s');
					$up_where['dh_message']=$_REQUEST['dh_message'];
					$up_where['dh_status']=$_REQUEST['dh_status'];
					$up_where['arrive_status']=$_REQUEST['arrive_status'];
					$up_where['flow_status']=$_REQUEST['flow_status'];
					$up_where['submit_info']=NULL;
					if($_REQUEST['flow_status']==1){
						//发送提醒
						$to_user['id']=$find_result['add_uid'];
						$to_user['username']=$find_result['add_user'];
						$to_users_array[]=$to_user;
						if($find_result['type']==7){
							$this->alert_send('打回人员需求',$to_users_array,'申请单编号:'.$find_result['order_number']);
						}elseif($find_result['type']==5){
							$this->alert_send('打回任务管理',$to_users_array,'申请单编号:'.$find_result['order_number'].'<a href="javascript:;" url="'.__APP__.'/Index/task_list/pid/'.$find_result['pid'].'" class="tiaoz">点击跳转</a>');
						}
					}
				}else{
					if($find_result['status']!=1){
						unset($up_where);
					}
				}
				break;
			case 1:
				$up_where['audit1_uid']=NULL;$up_where['audit1_date']=NULL;$up_where['audit1_message']=NULL;
				$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
				$up_where['audit3_uid']=NULL;$up_where['audit3_date']=NULL;$up_where['audit3_message']=NULL;
				$up_where['audit4_uid']=NULL;$up_where['audit4_date']=NULL;$up_where['audit4_message']=NULL;
				$up_where['audit5_uid']=NULL;$up_where['audit5_date']=NULL;$up_where['audit5_message']=NULL;
				if(!empty($_REQUEST['uuid'])){
					if($find_result['status']!=-1){
						unset($up_where);
					}else{
						$up_where['flow_status']=1;
						$up_where['status']=1;
						$up_where['post_uid']=$this->login_id;
						$up_where['post_date']=date('Y-m-d H:i:s');
						//发送提醒
						if($type==7){
							$relationship=$this->user_list_ajax_relationship(1,$find_result['add_uid']);
							$user=$this->get_user($relationship['audit_uid']);
                            $to_user['id']=$user['id'];
                            $to_user['username']=$user['username'];
                            $to_users_array[]=$to_user;
                            $this->alert_send('人员需求',$to_users_array,'申请单编号:'.$find_result['order_number']);
							if($user['openid']){
								$this->send_audit_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Index/person_demand_detail/id/'.$find_result['audit_id'].'/audit/sh&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的审核流程，请及时处理。','人员需求','申请单号【'.$find_result['order_number'].'】',$find_result['add_user'],substr($find_result['add_date'],0,10),NULL);
                            }
						}
					}
				}else{
					$up_where['status']=1;
					if($sta['audit_sort']!=$status){
						unset($up_where);
					}
				}
				break;
			case 2:
				if($type==6){
					if($find_result['status']!=1){
						unset($up_where);
					}else{
						$up_where['status']=$status;
						$up_where['audit1_uid']=$this->login_id;
						$up_where['audit1_date']=date('Y-m-d H:i:s');
					}
				}else{
					$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
					$up_where['audit3_uid']=NULL;$up_where['audit3_date']=NULL;$up_where['audit3_message']=NULL;
					$up_where['audit4_uid']=NULL;$up_where['audit4_date']=NULL;$up_where['audit4_message']=NULL;
					$up_where['audit5_uid']=NULL;$up_where['audit5_date']=NULL;$up_where['audit5_message']=NULL;
					if(!empty($_REQUEST['uuid'])){
						if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
							$up_where['status']=$status;
							$up_where['flow_status']=1;
							if($find_result['status']!=$find_result['arrive_status']){
								unset($up_where);
							}else{
								if($find_result['arrive_status']==-1){
									$up_where['post_uid']=$this->login_id;
									$up_where['post_date']=date('Y-m-d H:i:s');
								}else{
									$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
									$up_where['audit'.$find_result['arrive_status'].'_date']=date('Y-m-d H:i:s');
									$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit_message'];
									$up_where['submit_info']=$_REQUEST['audit_message'];
								}
							}
						}else{
							if($find_result['status']!=1){
								unset($up_where);
							}else{
								$up_where['status']=$sta['audit_sort'];
								$up_where['audit1_uid']=$this->login_id;
								$up_where['audit1_date']=date('Y-m-d H:i:s');
								$up_where['audit1_message']=$_REQUEST['audit_message'];
							}
						}
						if(!empty($up_where)){
							if($type==7){
								$audit_arr=explode(',',$sta['audit_uid']);
								foreach($audit_arr as $key=>$value){
									$user=$this->get_user($value);
									$to_user['id']=$user['id'];
									$to_user['username']=$user['username'];
									$to_users_array[]=$to_user;
									$this->alert_send('人员需求',$to_users_array,'申请单编号:'.$find_result['order_number']);
									if($user['openid']){
										$this->send_audit_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Index/person_demand_detail/id/'.$find_result['audit_id'].'/audit/sh&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的审核流程，请及时处理。','人员需求','申请单号【'.$find_result['order_number'].'】',$find_result['add_user'],substr($find_result['add_date'],0,10),NULL);
									}
								}
							}elseif($type==5){
								$audit_arr=explode(',',$sta['audit_uid']);
								foreach($audit_arr as $key=>$value){
									$user=$this->get_user($value);
									$to_user['id']=$user['id'];
									$to_user['username']=$user['username'];
									$to_users_array[]=$to_user;
									$this->alert_send('任务管理审核流程',$to_users_array,'任务单号:'.$find_result['order_number']);
									if($user['openid']){
										$this->send_audit_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Project/task_detail/id/'.$find_result['audit_id'].'/audit/sh&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的审核流程，请及时处理。','任务管理','申请单号【'.$find_result['order_number'].'】',$find_result['add_user'],substr($find_result['add_date'],0,10),NULL);
									}
								}
							}
						}
					}else{
						$up_where['status']=$status;
						if($find_result['flow_status']==-1){
							if($find_result['dh_status']!=$status){
								unset($up_where);
							}
						}else{
							if($sta['audit_sort']!=$status){
								unset($up_where);
							}
						}
					}
				}
				break;
			case 3:
				$up_where['audit3_uid']=NULL;$up_where['audit3_date']=NULL;$up_where['audit3_message']=NULL;
				$up_where['audit4_uid']=NULL;$up_where['audit4_date']=NULL;$up_where['audit4_message']=NULL;
				$up_where['audit5_uid']=NULL;$up_where['audit5_date']=NULL;$up_where['audit5_message']=NULL;
				if(!empty($_REQUEST['uuid'])){
					if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
						$up_where['flow_status']=1;
						$up_where['status']=$status;
						if($find_result['status']!=$find_result['arrive_status']){
							unset($up_where);
						}else{
							if($find_result['arrive_status']==-1){
								$up_where['post_uid']=$this->login_id;
								$up_where['post_date']=date('Y-m-d H:i:s');
							}else{
								$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
								$up_where['audit'.$find_result['arrive_status'].'_date']=date('Y-m-d H:i:s');
								$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit_message'];
								$up_where['submit_info']=$_REQUEST['audit_message'];
							}
						}
					}else{
						if($find_result['status']!=2){
							unset($up_where);
						}else{
							$up_where['status']=$status;
							$up_where['audit2_uid']=$this->login_id;
							$up_where['audit2_date']=date('Y-m-d H:i:s');
							$up_where['audit2_message']=$_REQUEST['audit_message'];
						}
					}
					if(!empty($up_where)){
						if($type==7){
							$audit_arr=explode(',',$sta['audit_uid']);
							foreach($audit_arr as $key=>$value){
								$user=$this->get_user($value);
								$to_user['id']=$user['id'];
								$to_user['username']=$user['username'];
								$to_users_array[]=$to_user;
								$this->alert_send('人员需求',$to_users_array,'申请单编号:'.$find_result['order_number']);
								if($user['openid']){
									$this->send_audit_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Index/person_demand_detail/id/'.$find_result['audit_id'].'/audit/sh&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的审核流程，请及时处理。','人员需求','申请单号【'.$find_result['order_number'].'】',$find_result['add_user'],substr($find_result['add_date'],0,10),NULL);
								}
							}
						}
					}
				}else{
					$up_where['status']=$status;
					if($find_result['flow_status']==-1){
						if($find_result['dh_status']!=$status){
							unset($up_where);
						}
					}else{
						if($sta['audit_sort']!=$status){
							unset($up_where);
						}
					}
				}
				break;
			case 4:
				$up_where['audit4_uid']=NULL;$up_where['audit4_date']=NULL;$up_where['audit4_message']=NULL;
				$up_where['audit5_uid']=NULL;$up_where['audit5_date']=NULL;$up_where['audit5_message']=NULL;
				if(!empty($_REQUEST['uuid'])){
					if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
						$up_where['flow_status']=1;
						$up_where['status']=$status;
						if($find_result['status']!=$find_result['arrive_status']){
							unset($up_where);
						}else{
							if($find_result['arrive_status']==-1){
								$up_where['post_uid']=$this->login_id;
								$up_where['post_date']=date('Y-m-d H:i:s');
							}else{
								$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
								$up_where['audit'.$find_result['arrive_status'].'_date']=date('Y-m-d H:i:s');
								$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit_message'];
								$up_where['submit_info']=$_REQUEST['audit_message'];
							}
						}
					}else{
						if($find_result['status']!=3){
							unset($up_where);
						}else{
							$up_where['status']=$status;
							$up_where['audit3_uid']=$this->login_id;
							$up_where['audit3_date']=date('Y-m-d H:i:s');
							$up_where['audit3_message']=$_REQUEST['audit_message'];
						}
					}
					if(!empty($up_where)){
						if($type==7){
							$audit_arr=explode(',',$sta['audit_uid']);
							foreach($audit_arr as $key=>$value){
								$user=$this->get_user($value);
								$to_user['id']=$user['id'];
								$to_user['username']=$user['username'];
								$to_users_array[]=$to_user;
								$this->alert_send('人员需求',$to_users_array,'申请单编号:'.$find_result['order_number']);
								if($user['openid']){
									$this->send_audit_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Index/person_demand_detail/id/'.$find_result['audit_id'].'/audit/sh&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的审核流程，请及时处理。','人员需求','申请单号【'.$find_result['order_number'].'】',$find_result['add_user'],substr($find_result['add_date'],0,10),NULL);
								}
							}
						}
					}
				}else{
					$up_where['status']=$status;
					if($find_result['flow_status']==-1){
						if($find_result['dh_status']!=$status){
							unset($up_where);
						}
					}else{
						if($sta['audit_sort']!=$status){
							unset($up_where);
						}
					}
				}
				break;
			case 5:
				$up_where['audit5_uid']=NULL;$up_where['audit5_date']=NULL;$up_where['audit5_message']=NULL;
				if(!empty($_REQUEST['uuid'])){
					if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
						$up_where['flow_status']=1;
						$up_where['status']=$status;
						if($find_result['status']!=$find_result['arrive_status']){
							unset($up_where);
						}else{
							if($find_result['arrive_status']==-1){
								$up_where['post_uid']=$this->login_id;
								$up_where['post_date']=date('Y-m-d H:i:s');
							}else{
								$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
								$up_where['audit'.$find_result['arrive_status'].'_date']=date('Y-m-d H:i:s');
								$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit_message'];
								$up_where['submit_info']=$_REQUEST['audit_message'];
							}
						}
					}else{
						if($find_result['status']!=4){
							unset($up_where);
						}else{
							$up_where['status']=$status;
							$up_where['audit4_uid']=$this->login_id;
							$up_where['audit4_date']=date('Y-m-d H:i:s');
							$up_where['audit4_message']=$_REQUEST['audit_message'];
						}
					}
					if(!empty($up_where)){
						if($type==7){
							$audit_arr=explode(',',$sta['audit_uid']);
							foreach($audit_arr as $key=>$value){
								$user=$this->get_user($value);
								$to_user['id']=$user['id'];
								$to_user['username']=$user['username'];
								$to_users_array[]=$to_user;
								$this->alert_send('人员需求',$to_users_array,'申请单编号:'.$find_result['order_number']);
								if($user['openid']){
									$this->send_audit_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Index/person_demand_detail/id/'.$find_result['audit_id'].'/audit/sh&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的审核流程，请及时处理。','人员需求','申请单号【'.$find_result['order_number'].'】',$find_result['add_user'],substr($find_result['add_date'],0,10),NULL);
								}
							}
						}
					}
				}else{
					$up_where['status']=$status;
					if($find_result['flow_status']==-1){
						if($find_result['dh_status']!=$status){
							unset($up_where);
						}
					}else{
						if($sta['audit_sort']!=$status){
							unset($up_where);
						}
					}
				}
				break;
			case 6:
				if($find_result['status']!=5){
					unset($up_where);
				}else{
					$up_where['status']=$status;
					$up_where['audit5_uid']=$this->login_id;
					$up_where['audit5_date']=date('Y-m-d H:i:s');
					$up_where['audit5_message']=$_REQUEST['audit_message'];
				}
				break;
		}
		if($_REQUEST['submit_info']){$up_where['submit_info']=$_REQUEST['submit_info'];}
        $data['status']=$db_audit_main->save($up_where);
		echo json_encode($data);die;
	}

	//登录-->判断
	function do_login(){
		parent::do_login();
	}

	//登录 designed by:zhangsen 2017-04-24
	function login(){
		if(cookie('username')){
			$this->assign('username',cookie('username'));
		}
		// $db_login=M('db_login');
		// $date=strtotime(date("Y-m-d"));
		// $where['_string']="find_in_set(".$date.",date)";
		// $where['sta']=1;
		// $result=$db_login->where($where)->find();
		// if(empty($result)){
			// for($i=1;$i<100;$i++){
				// $dates=date("Y-m-d",strtotime("".-$i." day"));
				// $date=strtotime($dates);
				// $where['_string']="find_in_set(".$date.",date)";
				// $where['sta']=1;
				// $result=$db_login->where($where)->find();
				// if($result){break;}
			// }
		// }
		// $db_user=M('db_user');
		// $where_f['id']=$result['uid'];
		// $name=$db_user->where($where_f)->find();
		// if(!empty($name['username1'])){
			// $result['name']=$name['username1'];
		// }else{
			// $result['name']=$name['username'];
		// }
		// $this->assign('result',$result);
		$this->display('Index/login');
	}

	//个人-->我参与的项目 designed by:zhangsen 2017-09-29
	function my_project(){
		//赋值
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		if(!empty($_REQUEST['center_id'])){$center_id=$_REQUEST['center_id'];}else{$center_id=-10;}
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['status'])){$status=$_REQUEST['status'];}else{$status=1;}
		$this->assign('status',$status);
		//项目状态筛选
		$this->assign('project_status',$this->get_db_universal_type(4));
		//列表
		$db_project=M('db_project');
		if(!empty($keyword))
		{
			$map['project_num']=array('like','%'.$keyword.'%');
			$map['project_name']=array('like','%'.$keyword.'%');
			$map['manager_name']=array('like','%'.$keyword.'%');
			$map['director_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where['_complex']=$map;
		}
		if($center_id!=-10){$where['center_id']=$center_id;}
		if($status!=-10){$where['db_project.status']=$status;}
		$string=NULL;
		if($this->get_is_project()){
			$string.="(manager_uid=".$this->login_id.") or (director_uid=".$this->login_id.") or";
		}
		if($this->get_is_project_function()){
			$db_project_function=M('db_project_function'); 
			$where_f['uid']=$this->login_id;
			$where_f['start_date']=array('elt',date("Y-m-d"));
			$where_f['end_date']=array('egt',date("Y-m-d"));
			$result_f=$db_project_function->where($where_f)->select();
			foreach($result_f as $key=>$value){
				$pids.=$value['pid'].',';
			}
			$string.="(db_project.id in (".rtrim($pids,',').")) or";
		}
		if($this->get_is_project_user()){
			$string.='(find_in_set("'.$this->login_id.'",project_uids)) or';
			$t_day=date('Y-m-d');
			$str="(SELECT db_project.id,db_project.project_num,db_project.project_name,db_project.status,db_project_user.pid,db_project_user.uid,db_project_user.nature,db_project_user.come_date FROM `db_project` inner join db_project_user on db_project.id=db_project_user.pid LEFT JOIN db_user on db_project_user.uid=db_user.id WHERE ( db_project.`center_id` = 130005 ) AND (('".$t_day."'>=come_date and '".$t_day."'<`out_date`) or ('".$t_day."'>=come_date and out_date is NULL)) and db_user.is_project=1 and db_user.status=1 and db_project_user.uid='".$this->login_id."' group by pid) ORDER BY project_num desc,come_date desc";
			$Model=M();
			$result_s=$Model->query($str);
			if($result_s){
				foreach($result_s as $key=>$value){
					$yy_pids.=$value['id'].',';
				}
				$string.="(db_project.id in (".rtrim($yy_pids,',').")) or";
			}
		}
		if($string){
			$where['_string']=rtrim($string,'or');
			$count=$db_project->field('db_project.id')->join('left join db_project_bg on db_project.id=db_project_bg.pid')->where($where)->count();
			$Page = new \Think\Page($count,15);
			$show=$Page->show();
			$result=$db_project->field('db_project.*')->join('left join db_project_bg on db_project.id=db_project_bg.pid')->where($where)->order('db_project.add_date desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		}
		//记录数
		$db_project_uploads=M('db_project_uploads');
		foreach($result as $key=>$value)
		{
			$where_p['pid']=$value['id'];
			$result[$key]['num']=$db_project_uploads->where($where_p)->count();
		}
		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->display();
	}

	//搜库-->课件资料库 designed by:wangyitian 2017-08-09
	function training_list(){
		parent::check_permission('KJ');
		//筛选
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		$ids_array=explode(',',$_REQUEST['ids']);
		$this->assign('ids',$_REQUEST['ids']);
		//功能显示判断
		$db_universal_type=M('db_universal_type');
		$where_cc['type']=10;
		$where_cc['name1']=1;
		$sz_status=$db_universal_type->where($where_cc)->find();
		$this->assign('sz_status',$sz_status);
		$db_library_main=M('db_library_main');
		$db_universal_label_type=M('db_universal_label_type');
		//所属中心筛选
		$center_type=$this->get_oa_dep_list();
		if($sz_status['name4']==1){
			foreach($center_type as $key=>$value)
			{
				$where_c['_string']="find_in_set(".$value['id'].",center_id)";
				$where_c['type']=1;
				$c_times=$db_library_main->where($where_c)->count();
				$center_type[$key]['times']=$c_times;
			}
		}
		$this->assign('center_type',$center_type);
		//筛选判断
		$screen=$this->library_type_list(1);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
			if($sz_status['name4']==1){
				//标签统计
				foreach($value['second'] as $kk=>$vv)
				{
					if($vv['second_name']!='全部')
					{
						$where_type['_string']='find_in_set("'.$vv['id'].'",sort_id)';
						$times=$db_universal_label_type->where($where_type)->count();
						$screen[$key]['second'][$kk]['times']=$times;
					}
				}
			}
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		//排序
		if(!empty($_REQUEST['action1'])){$action1=$_REQUEST['action1'];}
		$this->assign('action1',$action1);
		if(!empty($_REQUEST['action2'])){$action2=$_REQUEST['action2'];}
		$this->assign('action2',$action2);
		if(!empty($_REQUEST['action3'])){$action3=$_REQUEST['action3'];}elseif(empty($_REQUEST['action1']) and empty($_REQUEST['action2']) and empty($_REQUEST['action3'])){$action3='down';}
		$this->assign('action3',$action3);
		$db_library_main=M('db_library_main');
		if(!empty($keyword))
		{
			$map['name']=array('like','%'.$keyword.'%');
			$map['file_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where['_complex']=$map;
		}
		if(get_permission('KJ',1)){
			if(get_permission('KJ',NULL,2)){
				$where['_string']="((status=2) or (find_in_set(".$this->login_center_id.",center_id)))";
			}elseif(get_permission('KJ',NULL,3)){
				$where['_string']="((status=2) or (db_audit_main.add_uid=".$this->login_id."))";
			}
		}
		elseif(get_permission('KJ',2)){
			if(get_permission('KJ',NULL,2)){
				$where['_string']="(find_in_set(".$this->login_center_id.",center_id))";
			}elseif(get_permission('KJ',NULL,3)){
				$where['_string']="((status=2 and find_in_set(".$this->login_center_id.",center_id)) or (db_audit_main.add_uid=".$this->login_id."))";
			}elseif(get_permission('KJ',NULL,4)){
				$where['_string']="(status=2 and find_in_set(".$this->login_center_id.",center_id))";
			}
		}
		elseif(get_permission('KJ',3)){
			$where['db_audit_main.add_uid']=$this->login_id;
		}
		if(!get_permission('KJ',2)){
			if($center_id!=-10){
				$where[]="find_in_set(".$_REQUEST['center_id'].",center_id)";
			}
		}
		$where['db_library_main.type']=1;
		//排序
		if($action1=='up'){
			$order_str="section desc,zd_date desc,pr.praisect";
		}elseif($action1=='down'){
			$order_str="section desc,zd_date desc,pr.praisect desc";
		}
		if($action2=='up'){
			$order_str="section desc,zd_date desc,py.replyct";
		}elseif($action2=='down'){
			$order_str="section desc,zd_date desc,py.replyct desc";
		}
		if($action3=='up'){
			$order_str="section desc,zd_date desc,db_library_main.add_date";
		}elseif($action3=='down'){
			$order_str="section desc,zd_date desc,db_library_main.add_date desc";
		}
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if($vv['tid']!=$qb_id){
				$ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['tid'].'",sort_id))) and ';
			}
		}
		if(!empty($ids_str)){$where[]=rtrim($ids_str,'and ');}
		$count=$db_library_main->field('db_library_main.id,center_id,name,file_name,file_url,remark,db_library_main.type,section,home,zd_date,db_audit_main.status,db_audit_main.add_uid,db_audit_main.add_date,db_audit_main.audit1_uid as audit_uid,db_audit_main.audit1_date as audit_date,pr.praisect,py.replyct')->join('db_audit_main on db_library_main.id=db_audit_main.audit_id')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->select();
		$Page = new \Think\Page(count($count),C('PAGE_LIST_ROWS'));
		$show=$Page->show();
		$result=$db_library_main->field('db_library_main.id,center_id,name,file_name,file_url,remark,db_library_main.type,section,home,zd_date,db_audit_main.status,db_audit_main.add_uid,db_audit_main.add_date,db_audit_main.audit1_uid as audit_uid,db_audit_main.audit1_date as audit_date,pr.praisect,py.replyct')->join('db_audit_main on db_library_main.id=db_audit_main.audit_id')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->limit($Page->firstRow.','.$Page->listRows)->select();
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['type_id']=1;
		$db_universal_label2=M('db_universal_label2');
		$db_library_reading=M('db_library_reading');
		foreach($result as $key=>$value)
		{
			//swf文件是否存在
			$file_url=explode('.',$value['file_url']);
			$swf_url=$file_url[0].'.swf';
			$swf_url=str_replace("/dms_erp/uploads", "./uploads",$swf_url);
			if(file_exists($swf_url)) {
				$result[$key]['swfs']=1;
			}
			//音频文件是否存在
			if(!preg_match('/.pdf/',$value['file_url'])){
				$result[$key]['yp']=1;
			}
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['audit_user']=$this->get_username($value['audit_uid']);
			if(!empty($result[$key]))
			{
				$where_t['main_id']=$value['id'];
				$detail=$db_universal_label_type->where($where_t)->order('field(first_id,'.join(",",$first_sort).')')->select();
				foreach($detail as $kk=>$vv)
				{
					$where_detail['first_id']=$vv['first_id'];
					if(stripos($vv['sort_id'],",")!==FALSE)
					{
						unset($name);
						foreach(explode(",",$vv['sort_id']) as $kkk=>$vvv)
						{
							$where_detail['id']=$vvv;
							$name[$kkk]=$db_universal_label2->where($where_detail)->getField('second_name');
						}
						$result[$key]['types'][$kk]=join(",",$name);
					}
					else
					{
						$where_detail['id']=$vv['sort_id'];
						$result[$key]['types'][$kk]=$db_universal_label2->where($where_detail)->getField('second_name');
					}
				}
				$result[$key]['download_time']=$value['praisect'];
				$result[$key]['comment_num']=$value['replyct'];
			}
			//收藏判断
			$where_c['mid']=$value['id'];
			$where_c['collection']=2;
			$where_c['add_uid']=$this->login_id;
			$has=$db_library_reading->where($where_c)->find();
			if(!empty($has)){$result[$key]['collection']=2;}
			//分享判断
			$db_library_share=M('db_library_share');
			$where_s['mid']=$value['id'];
			$where_s['add_uid']=$this->login_id;
			$share=$db_library_share->where($where_s)->find();
			if(!empty($share)){$result[$key]['share']=1;$result[$key]['share_uids']=$share['share_uids'];}
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		if(get_permission('KJ',1,1)){$this->assign('shall',1);}
		//选择用户下拉菜单
		$this->assign("user_list",$this->get_all_department());
		$this->display();
	}

	//搜库-->课件资料库-->添加 designed by:wangyitian 2017-08-09
	function training_add(){
		parent::check_permission('KJ',NULL,1);
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$this->assign('screen',$this->library_type_list(1,NULL,NULL,1));
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$center_name=$this->get_oa_dep_name($login_center_id);
		$this->assign('center_name',$center_name);
		if($_REQUEST['action']=='add')
		{
			$db_library_main=M('db_library_main');
			if(get_permission('KJ',NULL,1)){
				$where_add['center_id']=join(',',$_REQUEST['center_ids']);
			}else{
				$where_add['center_id']=$login_center_id;
			}
			$where_add['name']=$_REQUEST['name'];
			$where_add['file_name']=$_REQUEST['file_name'];
			$where_add['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_add['remark']=$_REQUEST['remark'];}
			$where_add['type']=1;
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date("Y-m-d H:i:s");
			$id=$db_library_main->add($where_add);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$id;
			$where_t['type_id']=1;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_t['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_t['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->add($where_t);
				}
			}
			//添加
			$db_audit_main=M('db_audit_main');
			$where_j_n['order_number']=array('like','SK'.date('Ymd').'%');
			$judge_num=$db_audit_main->field('order_number')->where($where_j_n)->order('id desc')->select();
			if(empty($judge_num))
			{
				$num='001';
			}
			else
			{
				$num=substr($judge_num[0]['order_number'],10,3)+1;
				if(strlen($num)==1){$num='00'.$num;}
				elseif(strlen($num)==2){$num='0'.$num;}
			}
			$where_a['order_number']='SK'.date('Ymd').$num;
			$where_a['audit_id']=$id;
			$where_a['status']=1;
			$where_a['type']=6;
			$where_a['add_uid']=$this->login_id;
			$where_a['add_date']=date('Y-m-d H:i:s');
			$where_a['post_uid']=$this->login_id;
			$where_a['post_date']=date('Y-m-d H:i:s');
			$db_audit_main->add($where_a);
			$this->success("操作成功",__APP__."/Index/training_list");die;
		}
		$this->display();
	}
	
	//搜库-->课件资料库-->编辑 designed by:wangyitian 2017-08-09
	function training_edit(){
		parent::check_permission('KJ',NULL,1);
		//传值
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('ids',$_REQUEST['ids']);
		$this->assign('action1',$_REQUEST['action1']);
		$this->assign('action2',$_REQUEST['action2']);
		$this->assign('action3',$_REQUEST['action3']);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$this->assign('center_name',$this->get_oa_dep_name($this->login_center_id));
		//详情
		$db_library_main=M('db_library_main');
		$where_find['id']=$_REQUEST['id'];
		$training=$db_library_main->where($where_find)->find();
		foreach(explode(',',$training['center_id']) as $key=>$value){
			$name_center=$this->get_oa_dep_name($value);
			$str_name.=$name_center.',';
		}
		$training['center_name']=rtrim($str_name,',');
		$this->assign('training',$training);
		//类别表
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['main_id']=$_REQUEST['id'];
		$where_t['type_id']=1;
		$type=$db_universal_label_type->where($where_t)->select();
		$screen=$this->library_type_list(1,NULL,NULL,1);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				foreach($type as $k2=>$v2){
					$arr=explode(',',$v2['sort_id']);
					foreach($arr as $kk=>$vv){
						if($vv==$v1['id']){
							$screen[$key]['second'][$k1]['check']=1;
						}
					}
				}
			}
		}
		$this->assign('screen',$screen);
		if($_REQUEST['action']=='edit')
		{
			//判断是否修改过文件
			$file=$_REQUEST['file_url'];
			if($file!=$_REQUEST['file_url_old']){
				//删除原文件
				$file1=str_replace("/dms_erp/uploads", "./uploads", $_REQUEST['file_url_old']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$where_edit['id']=$_REQUEST['id'];
			if(get_permission('KJ',NULL,1)){
				$where_edit['center_id']=join(',',$_REQUEST['center_ids']);
			}
			$where_edit['name']=$_REQUEST['name'];
			$where_edit['file_name']=$_REQUEST['file_name'];
			$where_edit['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_edit['remark']=$_REQUEST['remark'];}else{$where_edit['remark']=NULL;}
			$db_library_main->save($where_edit);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$_REQUEST['id'];
			$where_t['type_id']=1;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_save['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_save['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->where($where_t)->save($where_save);
				}
			}
			$this->success("操作成功",__APP__."/Index/training_list/keyword/".$_REQUEST['keyword']."/center_id/".$_REQUEST['center_id']."/ids/".$_REQUEST['ids']."/action1/".$_REQUEST['action1']."/action2/".$_REQUEST['action2']."/action3/".$_REQUEST['action3']."&p=".$_SESSION['page']);die;
		}
		$this->display();
	}

	//搜库-->业务资料库 designed by:wangyitian 2017-08-31
	function business_list(){
		parent::check_permission('YW');
		//筛选
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		$ids_array=explode(',',$_REQUEST['ids']);
		$this->assign('ids',$_REQUEST['ids']);
		//功能显示判断
		$db_universal_type=M('db_universal_type');
		$where_cc['type']=10;
		$where_cc['name1']=2;
		$sz_status=$db_universal_type->where($where_cc)->find();
		$this->assign('sz_status',$sz_status);
		$db_library_main=M('db_library_main');
		$db_universal_label_type=M('db_universal_label_type');
		//所属中心筛选
		$center_type=$this->get_oa_dep_list();
		if($sz_status['name4']==1){
			foreach($center_type as $key=>$value)
			{
				$where_c['_string']="find_in_set(".$value['id'].",db_library_main.center_id)";
				$where_c['db_library_main.type']=2;
                $c_times=$db_library_main->join('db_audit_main on db_library_main.id=db_audit_main.audit_id')->where($where_c)->count('DISTINCT db_library_main.id');
                $center_type[$key]['times']=$c_times;
			}
		}
		$this->assign('center_type',$center_type);
		//筛选判断
		$screen=$this->library_type_list(4);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
			if($sz_status['name4']==1){
				//标签统计
                foreach($value['second'] as $kk=>$vv)
                {
                    $ids_str=NULL;
                    $where_type=NULL;
                    if($vv['second_name']!='全部')
                    {
                        $ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['id'].'",sort_id))) and ';
                        if($center_id!=-10){
                            $where_type['center_id']=$center_id;
                        }
                        if(!empty($ids_str)){$where_type[]=rtrim($ids_str,'and ');}
                        $times=$db_universal_label_type->join('db_library_main on db_universal_label_type.main_id=db_library_main.id')->join('db_audit_main on db_library_main.id=db_audit_main.audit_id')->where($where_type)->count('DISTINCT db_library_main.id');
                        $screen[$key]['second'][$kk]['times']=$times;
                    }
                }
			}
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		//排序
		if(!empty($_REQUEST['action1'])){$action1=$_REQUEST['action1'];}
		$this->assign('action1',$action1);
		if(!empty($_REQUEST['action2'])){$action2=$_REQUEST['action2'];}
		$this->assign('action2',$action2);
		if(!empty($_REQUEST['action3'])){$action3=$_REQUEST['action3'];}elseif(empty($_REQUEST['action1']) and empty($_REQUEST['action2']) and empty($_REQUEST['action3'])){$action3='down';}
		$this->assign('action3',$action3);
		$db_library_main=M('db_library_main');
		if(!empty($keyword))
		{
			$map['name']=array('like','%'.$keyword.'%');
			$map['file_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where['_complex']=$map;
		}
		if(get_permission('YW',1)){
			if(get_permission('YW',NULL,2)){
				$where['_string']="((status=2) or (find_in_set(".$this->login_center_id.",center_id)))";
			}elseif(get_permission('YW',NULL,3)){
				$where['_string']="((status=2) or (db_audit_main.add_uid=".$this->login_id."))";
			}
		}
		elseif(get_permission('YW',2)){
			if(get_permission('YW',NULL,2)){
				$where['_string']="(find_in_set(".$this->login_center_id.",center_id))";
			}elseif(get_permission('YW',NULL,3)){
				$where['_string']="((status=2 and find_in_set(".$this->login_center_id.",center_id)) or (db_audit_main.add_uid=".$this->login_id."))";
			}elseif(get_permission('YW',NULL,4)){
				$where['_string']="(status=2 and find_in_set(".$this->login_center_id.",center_id))";
			}
		}
		elseif(get_permission('YW',3)){
			$where['db_audit_main.add_uid']=$this->login_id;
		}
		if(!get_permission('YW',2)){
			if($center_id!=-10){
				$where[]="find_in_set(".$_REQUEST['center_id'].",center_id)";
			}
		}
		$where['db_library_main.type']=2;
		//排序
		if($action1=='up'){
			$order_str="section desc,zd_date desc,pr.praisect";
		}elseif($action1=='down'){
			$order_str="section desc,zd_date desc,pr.praisect desc";
		}
		if($action2=='up'){
			$order_str="section desc,zd_date desc,py.replyct";
		}elseif($action2=='down'){
			$order_str="section desc,zd_date desc,py.replyct desc";
		}
		if($action3=='up'){
			$order_str="section desc,zd_date desc,db_library_main.add_date";
		}elseif($action3=='down'){
			$order_str="section desc,zd_date desc,db_library_main.add_date desc";
		}
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if($vv['tid']!=$qb_id){
				$ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['tid'].'",sort_id))) and ';
			}
		}
		if(!empty($ids_str)){$where[]=rtrim($ids_str,'and ');}
		$count=$db_library_main->field('db_library_main.id,center_id,name,file_name,file_url,remark,db_library_main.type,section,home,zd_date,db_audit_main.status,db_audit_main.add_uid,db_audit_main.add_date,db_audit_main.audit1_uid as audit_uid,db_audit_main.audit1_date as audit_date,pr.praisect,py.replyct')->join('db_audit_main on db_library_main.id=db_audit_main.audit_id')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->select();
		$Page = new \Think\Page(count($count),C('PAGE_LIST_ROWS'));
		$show=$Page->show();
		$result=$db_library_main->field('db_library_main.id,center_id,name,file_name,file_url,remark,db_library_main.type,section,home,zd_date,db_audit_main.status,db_audit_main.add_uid,db_audit_main.add_date,db_audit_main.audit1_uid as audit_uid,db_audit_main.audit1_date as audit_date,pr.praisect,py.replyct')->join('db_audit_main on db_library_main.id=db_audit_main.audit_id')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->limit($Page->firstRow.','.$Page->listRows)->select();
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['type_id']=2;
		$db_universal_label2=M('db_universal_label2');
		$db_library_reading=M('db_library_reading');
		foreach($result as $key=>$value)
		{
			//swf文件是否存在
			$file_url=explode('.',$value['file_url']);
			$swf_url=$file_url[0].'.swf';
			$swf_url=str_replace("/dms_erp/uploads", "./uploads",$swf_url);
			if(file_exists($swf_url)) {
				$result[$key]['swfs']=1;
			}
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['audit_user']=$this->get_username($value['audit_uid']);
			if(!empty($result[$key]))
			{
				$where_t['main_id']=$value['id'];
				$detail=$db_universal_label_type->where($where_t)->order('field(first_id,'.join(",",$first_sort).')')->select();
				foreach($detail as $kk=>$vv)
				{
					$where_detail['first_id']=$vv['first_id'];
					if(stripos($vv['sort_id'],",")!==FALSE)
					{
						unset($name);
						foreach(explode(",",$vv['sort_id']) as $kkk=>$vvv)
						{
							$where_detail['id']=$vvv;
							$name[$kkk]=$db_universal_label2->where($where_detail)->getField('second_name');
						}
						$result[$key]['types'][$kk]=join(",",$name);
					}
					else
					{
						$where_detail['id']=$vv['sort_id'];
						$result[$key]['types'][$kk]=$db_universal_label2->where($where_detail)->getField('second_name');
					}
				}
				$result[$key]['download_time']=$value['praisect'];
				$result[$key]['comment_num']=$value['replyct'];
			}
			//收藏判断
			$where_c['mid']=$value['id'];
			$where_c['collection']=2;
			$where_c['add_uid']=$this->login_id;
			$has=$db_library_reading->where($where_c)->find();
			if(!empty($has)){$result[$key]['collection']=2;}
			//分享判断
			$db_library_share=M('db_library_share');
			$where_s['mid']=$value['id'];
			$where_s['add_uid']=$this->login_id;
			$share=$db_library_share->where($where_s)->find();
			if(!empty($share)){$result[$key]['share']=1;$result[$key]['share_uids']=$share['share_uids'];}
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		if(get_permission('YW',1,1)){$this->assign('shall',1);}
		//选择用户下拉菜单
		$this->assign("user_list",$this->get_all_department());
		$this->display();
	}

	//搜库-->业务资料库-->添加 designed by:wangyitian 2017-08-31
	function business_add(){
		parent::check_permission('YW',NULL,1);
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$this->assign('screen',$this->library_type_list(4,NULL,NULL,1));
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$center_name=$this->get_oa_dep_name($login_center_id);
		$this->assign('center_name',$center_name);
		if($_REQUEST['action']=='add')
		{
			$db_library_main=M('db_library_main');
			if(get_permission('YW',NULL,1)){
				$where_add['center_id']=join(',',$_REQUEST['center_ids']);
			}else{
				$where_add['center_id']=$login_center_id;
			}
			$where_add['name']=$_REQUEST['name'];
			$where_add['file_name']=$_REQUEST['file_name'];
			$where_add['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_add['remark']=$_REQUEST['remark'];}
			$where_add['type']=2;
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date("Y-m-d H:i:s");
			$id=$db_library_main->add($where_add);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$id;
			$where_t['type_id']=2;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_t['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_t['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->add($where_t);
				}
			}
			//添加
			$db_audit_main=M('db_audit_main');
			$where_j_n['order_number']=array('like','SK'.date('Ymd').'%');
			$judge_num=$db_audit_main->field('order_number')->where($where_j_n)->order('id desc')->select();
			if(empty($judge_num))
			{
				$num='001';
			}
			else
			{
				$num=substr($judge_num[0]['order_number'],10,3)+1;
				if(strlen($num)==1){$num='00'.$num;}
				elseif(strlen($num)==2){$num='0'.$num;}
			}
			$where_a['order_number']='SK'.date('Ymd').$num;
			$where_a['audit_id']=$id;
			$where_a['status']=1;
			$where_a['type']=6;
			$where_a['add_uid']=$this->login_id;
			$where_a['add_date']=date('Y-m-d H:i:s');
			$where_a['post_uid']=$this->login_id;
			$where_a['post_date']=date('Y-m-d H:i:s');
			$db_audit_main->add($where_a);
			$this->success("操作成功",__APP__."/Index/business_list");die;
		}
		$this->display();
	}
	
	//搜库-->业务资料库-->编辑 designed by:wangyitian 2017-08-31
	function business_edit(){
		parent::check_permission('YW',NULL,1);
		//传值
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('ids',$_REQUEST['ids']);
		$this->assign('action1',$_REQUEST['action1']);
		$this->assign('action2',$_REQUEST['action2']);
		$this->assign('action3',$_REQUEST['action3']);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		//详情
		$db_library_main=M('db_library_main');
		$where_find['id']=$_REQUEST['id'];
		$business=$db_library_main->where($where_find)->find();
		foreach(explode(',',$business['center_id']) as $key=>$value){
			$name_center=$this->get_oa_dep_name($value);
			$str_name.=$name_center.',';
		}
		$business['center_name']=rtrim($str_name,',');
		$this->assign('business',$business);
		//类别表
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['main_id']=$_REQUEST['id'];
		$where_t['type_id']=2;
		$type=$db_universal_label_type->where($where_t)->select();
		$screen=$this->library_type_list(4,NULL,NULL,1);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				foreach($type as $k2=>$v2){
					$arr=explode(',',$v2['sort_id']);
					foreach($arr as $kk=>$vv){
						if($vv==$v1['id']){
							$screen[$key]['second'][$k1]['check']=1;
						}
					}
				}
			}
		}
		$this->assign('screen',$screen);
		if($_REQUEST['action']=='edit')
		{
			//判断是否修改过文件
			$file=$_REQUEST['file_url'];
			if($file!=$_REQUEST['file_url_old']){
				//删除原文件
				$file1=str_replace("/dms_erp/uploads", "./uploads", $_REQUEST['file_url_old']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$where_edit['id']=$_REQUEST['id'];
			if(get_permission('YW',NULL,1)){
				$where_edit['center_id']=join(',',$_REQUEST['center_ids']);
			}
			$where_edit['name']=$_REQUEST['name'];
			$where_edit['file_name']=$_REQUEST['file_name'];
			$where_edit['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_edit['remark']=$_REQUEST['remark'];}else{$where_edit['remark']=NULL;}
			$db_library_main->save($where_edit);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$_REQUEST['id'];
			$where_t['type_id']=2;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_save['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_save['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->where($where_t)->save($where_save);
				}
			}
			$this->success("操作成功",__APP__."/Index/business_list/keyword/".$_REQUEST['keyword']."/center_id/".$_REQUEST['center_id']."/ids/".$_REQUEST['ids']."/action1/".$_REQUEST['action1']."/action2/".$_REQUEST['action2']."/action3/".$_REQUEST['action3']."&p=".$_SESSION['page']);die;
		}
		$this->display();
	}

	//搜库-->供应商库 designed by:wangyitian 2017-08-31
	function partner_list(){
		parent::check_permission('GY');
		//筛选
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		$ids_array=explode(',',$_REQUEST['ids']);
		$this->assign('ids',$_REQUEST['ids']);
		//功能显示判断
		$db_universal_type=M('db_universal_type');
		$where_cc['type']=10;
		$where_cc['name1']=4;
		$sz_status=$db_universal_type->where($where_cc)->find();
		$this->assign('sz_status',$sz_status);
		$db_library_main=M('db_library_main');
		$db_universal_label_type=M('db_universal_label_type');
		//所属中心筛选
		$center_type=$this->get_oa_dep_list();
		if($sz_status['name4']==1){
			foreach($center_type as $key=>$value)
			{
				$where_c['_string']="find_in_set(".$value['id'].",center_id)";
				$where_c['type']=4;
				$c_times=$db_library_main->where($where_c)->count();
				$center_type[$key]['times']=$c_times;
			}
		}
		$this->assign('center_type',$center_type);
		//筛选判断
		$screen=$this->library_type_list(10);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
			if($sz_status['name4']==1){
				//标签统计
				foreach($value['second'] as $kk=>$vv)
				{
					if($vv['second_name']!='全部')
					{
						$where_type['_string']='find_in_set("'.$vv['id'].'",sort_id)';
						$times=$db_universal_label_type->where($where_type)->count();
						$screen[$key]['second'][$kk]['times']=$times;
					}
				}
			}
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		//排序
		if(!empty($_REQUEST['action1'])){$action1=$_REQUEST['action1'];}
		$this->assign('action1',$action1);
		if(!empty($_REQUEST['action2'])){$action2=$_REQUEST['action2'];}
		$this->assign('action2',$action2);
		if(!empty($_REQUEST['action3'])){$action3=$_REQUEST['action3'];}elseif(empty($_REQUEST['action1']) and empty($_REQUEST['action2']) and empty($_REQUEST['action3'])){$action3='down';}
		$this->assign('action3',$action3);
		$db_library_main=M('db_library_main');
		if(!empty($keyword))
		{
			$map['name']=array('like','%'.$keyword.'%');
			$map['file_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where['_complex']=$map;
		}
		if(get_permission('GY',2)){
			if(get_permission('GY',NULL,3)){
				$where['_string']="((find_in_set(".$this->login_center_id.",center_id)) or (add_uid=".$this->login_id."))";
			}else{
				$where['_string']="(find_in_set(".$this->login_center_id.",center_id))";
			}
		}
		elseif(get_permission('GY',3)){
			$where['add_uid']=$this->login_id;
		}
		if(!get_permission('GY',2)){
			if($center_id!=-10){
				$where[]="find_in_set(".$_REQUEST['center_id'].",center_id)";
			}
		}
		$where['db_library_main.type']=4;
		//排序
		if($action1=='up'){
			$order_str="section desc,zd_date desc,pr.praisect";
		}elseif($action1=='down'){
			$order_str="section desc,zd_date desc,pr.praisect desc";
		}
		if($action2=='up'){
			$order_str="section desc,zd_date desc,py.replyct";
		}elseif($action2=='down'){
			$order_str="section desc,zd_date desc,py.replyct desc";
		}
		if($action3=='up'){
			$order_str="section desc,zd_date desc,db_library_main.add_date";
		}elseif($action3=='down'){
			$order_str="section desc,zd_date desc,db_library_main.add_date desc";
		}
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if($vv['tid']!=$qb_id){
				$ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['tid'].'",sort_id))) and ';
			}
		}
		if(!empty($ids_str)){$where[]=rtrim($ids_str,'and ');}
		$count=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->select();
		$Page = new \Think\Page(count($count),C('PAGE_LIST_ROWS'));
		$show=$Page->show();
		$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->limit($Page->firstRow.','.$Page->listRows)->select();
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['type_id']=4;
		$db_universal_label2=M('db_universal_label2');
		$db_library_partner=M('db_library_partner');
		$db_library_reading=M('db_library_reading');
		foreach($result as $key=>$value)
		{
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['audit_user']=$this->get_username($value['audit_uid']);
			if(!empty($result[$key]))
			{
				$where_t['main_id']=$value['id'];
				$detail=$db_universal_label_type->where($where_t)->order('field(first_id,'.join(",",$first_sort).')')->select();
				foreach($detail as $kk=>$vv)
				{
					$where_detail['first_id']=$vv['first_id'];
					if(stripos($vv['sort_id'],",")!==FALSE)
					{
						unset($name);
						foreach(explode(",",$vv['sort_id']) as $kkk=>$vvv)
						{
							$where_detail['id']=$vvv;
							$name[$kkk]=$db_universal_label2->where($where_detail)->getField('second_name');
						}
						$result[$key]['types'][$kk]=join(",",$name);
					}
					else
					{
						$where_detail['id']=$vv['sort_id'];
						$result[$key]['types'][$kk]=$db_universal_label2->where($where_detail)->getField('second_name');
					}
				}
				$result[$key]['download_time']=$value['praisect'];
				$result[$key]['comment_num']=$value['replyct'];
				//沟通记录数
				$where_p['m_id']=$value['id'];
				$result[$key]['partner_num']=$db_library_partner->where($where_p)->count();
			}
			//收藏判断
			$where_c['mid']=$value['id'];
			$where_c['collection']=2;
			$where_c['add_uid']=$this->login_id;
			$has=$db_library_reading->where($where_c)->find();
			if(!empty($has)){$result[$key]['collection']=2;}
			//分享判断
			$db_library_share=M('db_library_share');
			$where_s['mid']=$value['id'];
			$where_s['add_uid']=$this->login_id;
			$share=$db_library_share->where($where_s)->find();
			if(!empty($share)){$result[$key]['share']=1;$result[$key]['share_uids']=$share['share_uids'];}
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		if(get_permission('GY',1,1)){$this->assign('shall',1);}
		//选择用户下拉菜单
		$this->assign("user_list",$this->get_all_department());
		$this->display();
	}

	//搜库-->供应商库-->添加 designed by:wangyitian 2017-08-31
	function partner_add(){
		parent::check_permission('GY',NULL,1);
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$this->assign('screen',$this->library_type_list(10,NULL,NULL,1));
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$center_name=$this->get_oa_dep_name($login_center_id);
		$this->assign('center_name',$center_name);
		if($_REQUEST['action']=='add')
		{
			$db_library_main=M('db_library_main');
			if(get_permission('GY',NULL,1)){
				$where_add['center_id']=join(',',$_REQUEST['center_ids']);
			}else{
				$where_add['center_id']=$login_center_id;
			}
			$where_add['name']=$_REQUEST['name'];
			$where_add['file_name']=$_REQUEST['file_name'];
			$where_add['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_add['remark']=$_REQUEST['remark'];}
			$where_add['type']=4;
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date("Y-m-d H:i:s");
			$id=$db_library_main->add($where_add);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$id;
			$where_t['type_id']=4;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_t['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_t['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->add($where_t);
				}
			}
			$this->success("操作成功",__APP__."/Index/partner_list");die;
		}
		$this->display();
	}
	
	//搜库-->供应商库-->编辑 designed by:wangyitian 2017-08-31
	function partner_edit(){
		parent::check_permission('GY',NULL,1);
		//传值
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('ids',$_REQUEST['ids']);
		$this->assign('action1',$_REQUEST['action1']);
		$this->assign('action2',$_REQUEST['action2']);
		$this->assign('action3',$_REQUEST['action3']);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		//详情
		$db_library_main=M('db_library_main');
		$where_find['id']=$_REQUEST['id'];
		$partner=$db_library_main->where($where_find)->find();
		foreach(explode(',',$partner['center_id']) as $key=>$value){
			$name_center=$this->get_oa_dep_name($value);
			$str_name.=$name_center.',';
		}
		$partner['center_name']=rtrim($str_name,',');
		$this->assign('partner',$partner);
		//类别表
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['main_id']=$_REQUEST['id'];
		$where_t['type_id']=4;
		$type=$db_universal_label_type->where($where_t)->select();
		$screen=$this->library_type_list(10,NULL,NULL,1);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				foreach($type as $k2=>$v2){
					$arr=explode(',',$v2['sort_id']);
					foreach($arr as $kk=>$vv){
						if($vv==$v1['id']){
							$screen[$key]['second'][$k1]['check']=1;
						}
					}
				}
			}
		}
		$this->assign('screen',$screen);
		if($_REQUEST['action']=='edit')
		{
			//判断是否修改过文件
			$file=$_REQUEST['file_url'];
			if($file!=$_REQUEST['file_url_old']){
				//删除原文件
				$file1=str_replace("/dms_erp/uploads", "./uploads", $_REQUEST['file_url_old']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$where_edit['id']=$_REQUEST['id'];
			if(get_permission('YW',NULL,1)){
				$where_edit['center_id']=join(',',$_REQUEST['center_ids']);
			}
			$where_edit['name']=$_REQUEST['name'];
			$where_edit['file_name']=$_REQUEST['file_name'];
			$where_edit['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_edit['remark']=$_REQUEST['remark'];}else{$where_edit['remark']=NULL;}
			$db_library_main->save($where_edit);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$_REQUEST['id'];
			$where_t['type_id']=4;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_save['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_save['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->where($where_t)->save($where_save);
				}
			}
			$this->success("操作成功",__APP__."/Index/partner_list/keyword/".$_REQUEST['keyword']."/center_id/".$_REQUEST['center_id']."/ids/".$_REQUEST['ids']."/action1/".$_REQUEST['action1']."/action2/".$_REQUEST['action2']."/action3/".$_REQUEST['action3']."&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//搜库-->内部专家库 designed by:zhangsen 2017-11-07
	function talent_list(){
		parent::check_permission('RC');
		//筛选
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		$ids_array=explode(',',$_REQUEST['ids']);
		$this->assign('ids',$_REQUEST['ids']);
		//功能显示判断
		$db_universal_type=M('db_universal_type');
		$where_cc['type']=10;
		$where_cc['name1']=5;
		$sz_status=$db_universal_type->where($where_cc)->find();
		$this->assign('sz_status',$sz_status);
		$db_library_main=M('db_library_main');
		$db_universal_label_type=M('db_universal_label_type');
		//所属中心筛选
		$center_type=$this->get_oa_dep_list();
		if($sz_status['name4']==1){
			foreach($center_type as $key=>$value)
			{
				$where_c['_string']="find_in_set(".$value['id'].",db_user.center_id)";
				$where_c['type']=5;
				$where_c['db_user.status']=1;
				$c_times=$db_library_main->join('left join db_user on db_library_main.name=db_user.id')->where($where_c)->count();
				$center_type[$key]['times']=$c_times;
			}
		}
		$this->assign('center_type',$center_type);
		//筛选判断
		$screen=$this->library_type_list(11);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
			if($sz_status['name4']==1){
				//标签统计
				foreach($value['second'] as $kk=>$vv)
				{
					if($vv['second_name']!='全部')
					{
						$where_type['_string']='find_in_set("'.$vv['id'].'",sort_id) and main_id in (SELECT id from db_library_main where type=5 and name in(SELECT id from db_user where status=1))';
						$times=$db_universal_label_type->where($where_type)->count();
						$screen[$key]['second'][$kk]['times']=$times;
					}
				}
			}
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		$db_library_main=M('db_library_main');
		if(!empty($keyword))
		{
			$map['db_user.username']=array('like','%'.$keyword.'%');
			$map['db_library_main.file_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where['_complex']=$map;
		}
		if(get_permission('RC',2)){
			if(get_permission('RC',NULL,3)){
				$where['_string']="((find_in_set(".$this->login_center_id.",db_user.center_id)) or (add_uid=".$this->login_id.") or name=".$this->login_id.")";
			}else{
				$where['_string']="(find_in_set(".$this->login_center_id.",db_user.center_id) or name=".$this->login_id.")";
			}
		}
		elseif(get_permission('RC',3)){
			$where['_string']="add_uid=".$this->login_id." or name=".$this->login_id;
		}
		if(!get_permission('RC',2)){
			if($center_id!=-10){
				$where[]="find_in_set(".$_REQUEST['center_id'].",db_user.center_id)";
			}
		}
		$where['db_library_main.type']=5;
		$where['db_user.status']=1;
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if($vv['tid']!=$qb_id){
				$ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['tid'].'",sort_id))) and ';
			}
		}
		if(!empty($ids_str)){$where[]=rtrim($ids_str,'and ');}
		$count=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct,db_user.username')->where($where)->join('left join db_user on db_library_main.name=db_user.id')->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->select();
		$Page = new \Think\Page(count($count),C('PAGE_LIST_ROWS'));
		$show=$Page->show();
		$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct,db_user.username,db_user.mobilephone,db_user.empl_id')->where($where)->join('left join db_user on db_library_main.name=db_user.id')->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order('section desc,zd_date desc,rank_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['type_id']=5;
		$db_universal_label2=M('db_universal_label2');
		$db_library_reading=M('db_library_reading');
		foreach($result as $key=>$value)
		{
			if($value['name']==$this->login_id){
				$this->assign('is_self',1);
			}
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['audit_user']=$this->get_username($value['audit_uid']);
			if(!empty($result[$key]))
			{
				$where_t['main_id']=$value['id'];
				$detail=$db_universal_label_type->where($where_t)->order('field(first_id,'.join(",",$first_sort).')')->select();
				foreach($detail as $kk=>$vv)
				{
					$where_detail['first_id']=$vv['first_id'];
					if(stripos($vv['sort_id'],",")!==FALSE)
					{
						unset($name);
						foreach(explode(",",$vv['sort_id']) as $kkk=>$vvv)
						{
							$where_detail['id']=$vvv;
							$name[$kkk]=$db_universal_label2->where($where_detail)->getField('second_name');
						}
						$result[$key]['types'][$kk]=join(",",$name);
					}
					else
					{
						$where_detail['id']=$vv['sort_id'];
						$result[$key]['types'][$kk]=$db_universal_label2->where($where_detail)->getField('second_name');
					}
				}
				$result[$key]['download_time']=$value['praisect'];
				$result[$key]['comment_num']=$value['replyct'];
			}
			//收藏判断
			$where_c['mid']=$value['id'];
			$where_c['collection']=2;
			$where_c['add_uid']=$this->login_id;
			$has=$db_library_reading->where($where_c)->find();
			if(!empty($has)){$result[$key]['collection']=2;}
			//分享判断
			$db_library_share=M('db_library_share');
			$where_s['mid']=$value['id'];
			$where_s['add_uid']=$this->login_id;
			$share=$db_library_share->where($where_s)->find();
			if(!empty($share)){$result[$key]['share']=1;$result[$key]['share_uids']=$share['share_uids'];}
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		if(get_permission('RC',1,1)){$this->assign('shall',1);}
		//选择用户下拉菜单
		$this->assign("user_list",$this->get_all_department());
		$this->display();
	}

	//搜库-->内部专家库-->添加 designed by:zhangsen 2017-11-07
	function talent_add(){
		parent::check_permission('RC',NULL,1);
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$this->assign('screen',$this->library_type_list(11,NULL,NULL,1));
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$center_name=$this->get_oa_dep_name($login_center_id);
		$this->assign('center_name',$center_name);
		//所有用户
		$this->assign('user_list',$this->get_all_username());
		if($_REQUEST['action']=='add')
		{
			//判断姓名是否重复
			$db_library_main=M('db_library_main');
			if(!empty($_REQUEST['name'])){
				$where_user['name']=$_REQUEST['name'];
				$user_list=$db_library_main->where($where_user)->find();
				if(!empty($user_list))
				{
					$this->error("该内部专家已存在！");die;
				}
			}
			$where_add['name']=$_REQUEST['name'];
			$where_add['file_name']=$_REQUEST['file_name'];
			$where_add['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_add['remark']=$_REQUEST['remark'];}
			$where_add['type']=5;
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date("Y-m-d H:i:s");
			$id=$db_library_main->add($where_add);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$id;
			$where_t['type_id']=5;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_t['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_t['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->add($where_t);
				}
			}
			$this->success("操作成功",__APP__."/Index/talent_list");die;
		}
		$this->display();
	}
	
	//搜库-->内部专家库-->编辑 designed by:zhangsen 2017-11-07
	function talent_edit(){
		parent::check_permission('RC',NULL,1);
		//传值
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('ids',$_REQUEST['ids']);
		$this->assign('action1',$_REQUEST['action1']);
		$this->assign('action2',$_REQUEST['action2']);
		$this->assign('action3',$_REQUEST['action3']);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		//所有用户
		$this->assign('user_list',$this->get_all_username());
		//详情
		$db_library_main=M('db_library_main');
		$where_find['id']=$_REQUEST['id'];
		$business=$db_library_main->where($where_find)->find();
		foreach(explode(',',$business['center_id']) as $key=>$value){
			$name_center=$this->get_oa_dep_name($value);
			$str_name.=$name_center.',';
		}
		$business['center_name']=rtrim($str_name,',');
		$this->assign('business',$business);
		//类别表
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['main_id']=$_REQUEST['id'];
		$where_t['type_id']=5;
		$type=$db_universal_label_type->where($where_t)->select();
		$screen=$this->library_type_list(11,NULL,NULL,1);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				foreach($type as $k2=>$v2){
					$arr=explode(',',$v2['sort_id']);
					foreach($arr as $kk=>$vv){
						if($vv==$v1['id']){
							$screen[$key]['second'][$k1]['check']=1;
						}
					}
				}
			}
		}
		$this->assign('screen',$screen);
		if($_REQUEST['action']=='edit')
		{
			//判断姓名是否重复
			$db_library_main=M('db_library_main');
			if(!empty($_REQUEST['name'])){
				$where_user['name']=$_REQUEST['name'];
				$where_user['id']=array('neq',$_REQUEST['id']);
				$user_list=$db_library_main->where($where_user)->find();
				if(!empty($user_list))
				{
					$this->error("该内部专家已存在！");die;
				}
			}
			//判断是否修改过文件
			$file=$_REQUEST['file_url'];
			if($file!=$_REQUEST['file_url_old']){
				//删除原文件
				$file1=str_replace("/dms_erp/uploads", "./uploads", $_REQUEST['file_url_old']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$where_edit['id']=$_REQUEST['id'];
			if(get_permission('RC',NULL,1)){
				$where_edit['center_id']=join(',',$_REQUEST['center_ids']);
			}
			$where_edit['name']=$_REQUEST['name'];
			$where_edit['file_name']=$_REQUEST['file_name'];
			$where_edit['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_edit['remark']=$_REQUEST['remark'];}else{$where_edit['remark']=NULL;}
			$db_library_main->save($where_edit);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$_REQUEST['id'];
			$where_t['type_id']=5;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_save['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_save['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->where($where_t)->save($where_save);
				}
			}
			$this->success("操作成功",__APP__."/Index/talent_list/keyword/".$_REQUEST['keyword']."/center_id/".$_REQUEST['center_id']."/ids/".$_REQUEST['ids']."/action1/".$_REQUEST['action1']."/action2/".$_REQUEST['action2']."/action3/".$_REQUEST['action3']."&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//搜库-->模板资料库 designed by:zhangsen 2017-11-07
	function template_list(){
		parent::check_permission('MB');
		//筛选
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		$ids_array=explode(',',$_REQUEST['ids']);
		$this->assign('ids',$_REQUEST['ids']);
		//功能显示判断
		$db_universal_type=M('db_universal_type');
		$where_cc['type']=10;
		$where_cc['name1']=6;
		$sz_status=$db_universal_type->where($where_cc)->find();
		$this->assign('sz_status',$sz_status);
		$db_library_main=M('db_library_main');
		$db_universal_label_type=M('db_universal_label_type');
		//所属中心筛选
		$center_type=$this->get_oa_dep_list();
		if($sz_status['name4']==1){
			foreach($center_type as $key=>$value)
			{
				$where_c['_string']="find_in_set(".$value['id'].",center_id)";
				$where_c['type']=6;
				$c_times=$db_library_main->where($where_c)->count();
				$center_type[$key]['times']=$c_times;
			}
		}
		$this->assign('center_type',$center_type);
		//筛选判断
		$screen=$this->library_type_list(12);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
			if($sz_status['name4']==1){
				//标签统计
				foreach($value['second'] as $kk=>$vv)
				{
					if($vv['second_name']!='全部')
					{
						$where_type['_string']='find_in_set("'.$vv['id'].'",sort_id)';
						$times=$db_universal_label_type->where($where_type)->count();
						$screen[$key]['second'][$kk]['times']=$times;
					}
				}
			}
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		//排序
		if(!empty($_REQUEST['action1'])){$action1=$_REQUEST['action1'];}
		$this->assign('action1',$action1);
		if(!empty($_REQUEST['action2'])){$action2=$_REQUEST['action2'];}
		$this->assign('action2',$action2);
		if(!empty($_REQUEST['action3'])){$action3=$_REQUEST['action3'];}elseif(empty($_REQUEST['action1']) and empty($_REQUEST['action2']) and empty($_REQUEST['action3'])){$action3='down';}
		$this->assign('action3',$action3);
		$db_library_main=M('db_library_main');
		if(!empty($keyword))
		{
			$map['name']=array('like','%'.$keyword.'%');
			$map['file_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where['_complex']=$map;
		}
		if(get_permission('MB',2)){
			if(get_permission('MB',NULL,3)){
				$where['_string']="((find_in_set(".$this->login_center_id.",center_id)) or (add_uid=".$this->login_id."))";
			}else{
				$where['_string']="(find_in_set(".$this->login_center_id.",center_id))";
			}
		}
		elseif(get_permission('MB',3)){
			$where['add_uid']=$this->login_id;
		}
		if(!get_permission('MB',2)){
			if($center_id!=-10){
				$where[]="find_in_set(".$_REQUEST['center_id'].",center_id)";
			}
		}
		$where['db_library_main.type']=6;
		//排序
		if($action1=='up'){
			$order_str="section desc,zd_date desc,pr.praisect";
		}elseif($action1=='down'){
			$order_str="section desc,zd_date desc,pr.praisect desc";
		}
		if($action2=='up'){
			$order_str="section desc,zd_date desc,py.replyct";
		}elseif($action2=='down'){
			$order_str="section desc,zd_date desc,py.replyct desc";
		}
		if($action3=='up'){
			$order_str="section desc,zd_date desc,db_library_main.add_date";
		}elseif($action3=='down'){
			$order_str="section desc,zd_date desc,db_library_main.add_date desc";
		}
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if($vv['tid']!=$qb_id){
				$ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['tid'].'",sort_id))) and ';
			}
		}
		if(!empty($ids_str)){$where[]=rtrim($ids_str,'and ');}
		$count=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->select();
		$Page = new \Think\Page(count($count),C('PAGE_LIST_ROWS'));
		$show=$Page->show();
		$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->limit($Page->firstRow.','.$Page->listRows)->select();
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['type_id']=6;
		$db_universal_label2=M('db_universal_label2');
		$db_library_reading=M('db_library_reading');
		foreach($result as $key=>$value)
		{
			//swf文件是否存在
			$file_url=explode('.',$value['file_url']);
			$swf_url=$file_url[0].'.swf';
			$swf_url=str_replace("/dms_erp/uploads", "./uploads",$swf_url);
			if(file_exists($swf_url)) {
				$result[$key]['swfs']=1;
			}
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['audit_user']=$this->get_username($value['audit_uid']);
			if(!empty($result[$key]))
			{
				$where_t['main_id']=$value['id'];
				$detail=$db_universal_label_type->where($where_t)->order('field(first_id,'.join(",",$first_sort).')')->select();
				foreach($detail as $kk=>$vv)
				{
					$where_detail['first_id']=$vv['first_id'];
					if(stripos($vv['sort_id'],",")!==FALSE)
					{
						unset($name);
						foreach(explode(",",$vv['sort_id']) as $kkk=>$vvv)
						{
							$where_detail['id']=$vvv;
							$name[$kkk]=$db_universal_label2->where($where_detail)->getField('second_name');
						}
						$result[$key]['types'][$kk]=join(",",$name);
					}
					else
					{
						$where_detail['id']=$vv['sort_id'];
						$result[$key]['types'][$kk]=$db_universal_label2->where($where_detail)->getField('second_name');
					}
				}
				$result[$key]['download_time']=$value['praisect'];
				$result[$key]['comment_num']=$value['replyct'];
			}
			//收藏判断
			$where_c['mid']=$value['id'];
			$where_c['collection']=2;
			$where_c['add_uid']=$this->login_id;
			$has=$db_library_reading->where($where_c)->find();
			if(!empty($has)){$result[$key]['collection']=2;}
			//分享判断
			$db_library_share=M('db_library_share');
			$where_s['mid']=$value['id'];
			$where_s['add_uid']=$this->login_id;
			$share=$db_library_share->where($where_s)->find();
			if(!empty($share)){$result[$key]['share']=1;$result[$key]['share_uids']=$share['share_uids'];}
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		if(get_permission('MB',1,1)){$this->assign('shall',1);}
		//选择用户下拉菜单
		$this->assign("user_list",$this->get_all_department());
		$this->display();
	}

	//搜库-->模板资料库-->添加 designed by:zhangsen 2017-11-07
	function template_add(){
		parent::check_permission('MB',NULL,1);
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$this->assign('screen',$this->library_type_list(12,NULL,NULL,1));
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$center_name=$this->get_oa_dep_name($login_center_id);
		$this->assign('center_name',$center_name);
		if($_REQUEST['action']=='add')
		{
			$db_library_main=M('db_library_main');
			if(get_permission('MB',NULL,1)){
				$where_add['center_id']=join(',',$_REQUEST['center_ids']);
			}else{
				$where_add['center_id']=$login_center_id;
			}
			$where_add['name']=$_REQUEST['name'];
			$where_add['file_name']=$_REQUEST['file_name'];
			$where_add['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_add['remark']=$_REQUEST['remark'];}
			$where_add['type']=6;
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date("Y-m-d H:i:s");
			$id=$db_library_main->add($where_add);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$id;
			$where_t['type_id']=6;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_t['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_t['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->add($where_t);
				}
			}
			$this->success("操作成功",__APP__."/Index/template_list");die;
		}
		$this->display();
	}
	
	//搜库-->模板资料库-->编辑 designed by:zhangsen 2017-11-07
	function template_edit(){
		parent::check_permission('MB',NULL,1);
		//传值
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('ids',$_REQUEST['ids']);
		$this->assign('action1',$_REQUEST['action1']);
		$this->assign('action2',$_REQUEST['action2']);
		$this->assign('action3',$_REQUEST['action3']);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		//详情
		$db_library_main=M('db_library_main');
		$where_find['id']=$_REQUEST['id'];
		$business=$db_library_main->where($where_find)->find();
		foreach(explode(',',$business['center_id']) as $key=>$value){
			$name_center=$this->get_oa_dep_name($value);
			$str_name.=$name_center.',';
		}
		$business['center_name']=rtrim($str_name,',');
		$this->assign('business',$business);
		//类别表
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['main_id']=$_REQUEST['id'];
		$where_t['type_id']=6;
		$type=$db_universal_label_type->where($where_t)->select();
		$screen=$this->library_type_list(12,NULL,NULL,1);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				foreach($type as $k2=>$v2){
					$arr=explode(',',$v2['sort_id']);
					foreach($arr as $kk=>$vv){
						if($vv==$v1['id']){
							$screen[$key]['second'][$k1]['check']=1;
						}
					}
				}
			}
		}
		$this->assign('screen',$screen);
		if($_REQUEST['action']=='edit')
		{
			//判断是否修改过文件
			$file=$_REQUEST['file_url'];
			if($file!=$_REQUEST['file_url_old']){
				//删除原文件
				$file1=str_replace("/dms_erp/uploads", "./uploads", $_REQUEST['file_url_old']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$where_edit['id']=$_REQUEST['id'];
			if(get_permission('MB',NULL,1)){
				$where_edit['center_id']=join(',',$_REQUEST['center_ids']);
			}
			$where_edit['name']=$_REQUEST['name'];
			$where_edit['file_name']=$_REQUEST['file_name'];
			$where_edit['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_edit['remark']=$_REQUEST['remark'];}else{$where_edit['remark']=NULL;}
			$db_library_main->save($where_edit);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$_REQUEST['id'];
			$where_t['type_id']=6;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_save['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_save['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->where($where_t)->save($where_save);
				}
			}
			$this->success("操作成功",__APP__."/Index/template_list/keyword/".$_REQUEST['keyword']."/center_id/".$_REQUEST['center_id']."/ids/".$_REQUEST['ids']."/action1/".$_REQUEST['action1']."/action2/".$_REQUEST['action2']."/action3/".$_REQUEST['action3']."&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//搜库-->IP100资源库 designed by:zhangsen 2017-11-07
	function ip100_list(){
		parent::check_permission('IP');
		//筛选
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		$ids_array=explode(',',$_REQUEST['ids']);
		$this->assign('ids',$_REQUEST['ids']);
		//功能显示判断
		$db_universal_type=M('db_universal_type');
		$where_cc['type']=10;
		$where_cc['name1']=7;
		$sz_status=$db_universal_type->where($where_cc)->find();
		$this->assign('sz_status',$sz_status);
		$db_library_main=M('db_library_main');
		$db_universal_label_type=M('db_universal_label_type');
		//所属中心筛选
		$center_type=$this->get_oa_dep_list();
		if($sz_status['name4']==1){
			foreach($center_type as $key=>$value)
			{
				$where_c['_string']="find_in_set(".$value['id'].",center_id)";
				$where_c['type']=7;
				$c_times=$db_library_main->where($where_c)->count();
				$center_type[$key]['times']=$c_times;
			}
		}
		$this->assign('center_type',$center_type);
		//筛选判断
		$screen=$this->library_type_list(14);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
			if($sz_status['name4']==1){
				//标签统计
				foreach($value['second'] as $kk=>$vv)
				{
					if($vv['second_name']!='全部')
					{
						$where_type['_string']='find_in_set("'.$vv['id'].'",sort_id)';
						$times=$db_universal_label_type->where($where_type)->count();
						$screen[$key]['second'][$kk]['times']=$times;
					}
				}
			}
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		//排序
		if(!empty($_REQUEST['action1'])){$action1=$_REQUEST['action1'];}
		$this->assign('action1',$action1);
		if(!empty($_REQUEST['action2'])){$action2=$_REQUEST['action2'];}
		$this->assign('action2',$action2);
		if(!empty($_REQUEST['action3'])){$action3=$_REQUEST['action3'];}elseif(empty($_REQUEST['action1']) and empty($_REQUEST['action2']) and empty($_REQUEST['action3'])){$action3='down';}
		$this->assign('action3',$action3);
		$db_library_main=M('db_library_main');
		if(!empty($keyword))
		{
			$map['name']=array('like','%'.$keyword.'%');
			$map['file_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where['_complex']=$map;
		}
		if(get_permission('IP',2)){
			if(get_permission('IP',NULL,3)){
				$where['_string']="((find_in_set(".$this->login_center_id.",center_id)) or (add_uid=".$this->login_id."))";
			}else{
				$where['_string']="(find_in_set(".$this->login_center_id.",center_id))";
			}
		}
		elseif(get_permission('IP',3)){
			$where['add_uid']=$this->login_id;
		}
		if(!get_permission('IP',2)){
			if($center_id!=-10){
				$where[]="find_in_set(".$_REQUEST['center_id'].",center_id)";
			}
		}
		$where['db_library_main.type']=7;
		//排序
		if($action1=='up'){
			$order_str="section desc,zd_date desc,pr.praisect";
		}elseif($action1=='down'){
			$order_str="section desc,zd_date desc,pr.praisect desc";
		}
		if($action2=='up'){
			$order_str="section desc,zd_date desc,py.replyct";
		}elseif($action2=='down'){
			$order_str="section desc,zd_date desc,py.replyct desc";
		}
		if($action3=='up'){
			$order_str="section desc,zd_date desc,db_library_main.add_date";
		}elseif($action3=='down'){
			$order_str="section desc,zd_date desc,db_library_main.add_date desc";
		}
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if($vv['tid']!=$qb_id){
				$ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['tid'].'",sort_id))) and ';
			}
		}
		if(!empty($ids_str)){$where[]=rtrim($ids_str,'and ');}
		$count=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->select();
		$Page = new \Think\Page(count($count),C('PAGE_LIST_ROWS'));
		$show=$Page->show();
		$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->limit($Page->firstRow.','.$Page->listRows)->select();
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['type_id']=7;
		$db_universal_label2=M('db_universal_label2');
		$db_library_reading=M('db_library_reading');
		foreach($result as $key=>$value)
		{
			//swf文件是否存在
			$file_url=explode('.',$value['file_url']);
			$swf_url=$file_url[0].'.swf';
			$swf_url=str_replace("/dms_erp/uploads", "./uploads",$swf_url);
			if(file_exists($swf_url)) {
				$result[$key]['swfs']=1;
			}
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['audit_user']=$this->get_username($value['audit_uid']);
			if(!empty($result[$key]))
			{
				$where_t['main_id']=$value['id'];
				$detail=$db_universal_label_type->where($where_t)->order('field(first_id,'.join(",",$first_sort).')')->select();
				foreach($detail as $kk=>$vv)
				{
					$where_detail['first_id']=$vv['first_id'];
					if(stripos($vv['sort_id'],",")!==FALSE)
					{
						unset($name);
						foreach(explode(",",$vv['sort_id']) as $kkk=>$vvv)
						{
							$where_detail['id']=$vvv;
							$name[$kkk]=$db_universal_label2->where($where_detail)->getField('second_name');
						}
						$result[$key]['types'][$kk]=join(",",$name);
					}
					else
					{
						$where_detail['id']=$vv['sort_id'];
						$result[$key]['types'][$kk]=$db_universal_label2->where($where_detail)->getField('second_name');
					}
				}
				$result[$key]['download_time']=$value['praisect'];
				$result[$key]['comment_num']=$value['replyct'];
			}
			//收藏判断
			$where_c['mid']=$value['id'];
			$where_c['collection']=2;
			$where_c['add_uid']=$this->login_id;
			$has=$db_library_reading->where($where_c)->find();
			if(!empty($has)){$result[$key]['collection']=2;}
			//分享判断
			$db_library_share=M('db_library_share');
			$where_s['mid']=$value['id'];
			$where_s['add_uid']=$this->login_id;
			$share=$db_library_share->where($where_s)->find();
			if(!empty($share)){$result[$key]['share']=1;$result[$key]['share_uids']=$share['share_uids'];}
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		if(get_permission('IP',1,1)){$this->assign('shall',1);}
		//选择用户下拉菜单
		$this->assign("user_list",$this->get_all_department());
		$this->display();
	}

	//搜库-->IP100资源库-->添加 designed by:zhangsen 2017-11-07
	function ip100_add(){
		setcookie("file_type"); 
		unset($_COOKIE['file_type']);
		parent::check_permission('IP',NULL,1);
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$this->assign('screen',$this->library_type_list(14,NULL,NULL,1));
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$center_name=$this->get_oa_dep_name($login_center_id);
		$this->assign('center_name',$center_name);
		if($_REQUEST['action']=='add')
		{
			$db_library_main=M('db_library_main');
			if(get_permission('IP',NULL,1)){
				$where_add['center_id']=join(',',$_REQUEST['center_ids']);
			}else{
				$where_add['center_id']=$login_center_id;
			}
			$where_add['name']=$_REQUEST['name'];
			$where_add['file_name']=$_REQUEST['file_name'];
			$where_add['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_add['remark']=$_REQUEST['remark'];}
			$where_add['type']=7;
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date("Y-m-d H:i:s");
			$id=$db_library_main->add($where_add);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$id;
			$where_t['type_id']=7;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_t['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_t['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->add($where_t);
				}
			}
			$this->success("操作成功",__APP__."/Index/ip100_list");die;
		}
		$this->display();
	}
	
	//搜库-->IP100资源库-->编辑 designed by:zhangsen 2017-11-07
	function ip100_edit(){
		setcookie("file_type"); 
		unset($_COOKIE['file_type']);
		parent::check_permission('IP',NULL,1);
		//传值
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('ids',$_REQUEST['ids']);
		$this->assign('action1',$_REQUEST['action1']);
		$this->assign('action2',$_REQUEST['action2']);
		$this->assign('action3',$_REQUEST['action3']);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		//详情
		$db_library_main=M('db_library_main');
		$where_find['id']=$_REQUEST['id'];
		$business=$db_library_main->where($where_find)->find();
		foreach(explode(',',$business['center_id']) as $key=>$value){
			$name_center=$this->get_oa_dep_name($value);
			$str_name.=$name_center.',';
		}
		$business['center_name']=rtrim($str_name,',');
		$this->assign('business',$business);
		//类别表
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['main_id']=$_REQUEST['id'];
		$where_t['type_id']=7;
		$type=$db_universal_label_type->where($where_t)->select();
		$screen=$this->library_type_list(14,NULL,NULL,1);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				foreach($type as $k2=>$v2){
					$arr=explode(',',$v2['sort_id']);
					foreach($arr as $kk=>$vv){
						if($vv==$v1['id']){
							$screen[$key]['second'][$k1]['check']=1;
						}
					}
				}
			}
		}
		$this->assign('screen',$screen);
		if($_REQUEST['action']=='edit')
		{
			//判断是否修改过文件
			$file=$_REQUEST['file_url'];
			if($file!=$_REQUEST['file_url_old']){
				//删除原文件
				$file1=str_replace("/dms_erp/uploads", "./uploads", $_REQUEST['file_url_old']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$where_edit['id']=$_REQUEST['id'];
			if(get_permission('IP',NULL,1)){
				$where_edit['center_id']=join(',',$_REQUEST['center_ids']);
			}
			$where_edit['name']=$_REQUEST['name'];
			$where_edit['file_name']=$_REQUEST['file_name'];
			$where_edit['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_edit['remark']=$_REQUEST['remark'];}else{$where_edit['remark']=NULL;}
			$db_library_main->save($where_edit);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$_REQUEST['id'];
			$where_t['type_id']=7;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_save['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_save['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->where($where_t)->save($where_save);
				}
			}
			$this->success("操作成功",__APP__."/Index/ip100_list/keyword/".$_REQUEST['keyword']."/center_id/".$_REQUEST['center_id']."/ids/".$_REQUEST['ids']."/action1/".$_REQUEST['action1']."/action2/".$_REQUEST['action2']."/action3/".$_REQUEST['action3']."&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//资料库-->ajax操作 designed by:wangyitian 2017-08-31
	function library_ajax(){
		$db_library_main=M('db_library_main');
		$db_audit_main=M('db_audit_main');
		$where['id']=$_REQUEST['id'];
		if($_REQUEST['action']=='delete')
		{
			//删除文件
			$result=$db_library_main->where($where)->find();
			$file=str_replace("/dms_erp/uploads", "./uploads", $result['file_url']);
			if (file_exists($file)){
				@unlink($file);
			}
			if($result['type']==1 || $result['type']==2){
				//删除审核流程单
				$where_s['audit_id']=$_REQUEST['id'];
				$where_s['type']=6;
				$result_s=$db_audit_main->where($where_s)->delete();
			}
			//删除主单
			$result_bool=$db_library_main->where($where)->delete();
			//删除标签数据
			$db_universal_label_type=M('db_universal_label_type');
			$where_del['main_id']=$_REQUEST['id'];
			$where_del['type_id']=$result['type'];
			$db_universal_label_type->where($where_del)->delete();
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='download')
		{
			if($this->login_id!='1'){
				//记录阅读量
				$db_library_reading=M('db_library_reading');
				$where_add['mid']=$_REQUEST['id'];
				$where_add['add_uid']=$this->login_id;
				$where_add['add_date']=date("Y-m-d H:i:s");
				$db_library_reading->add($where_add);
			}
		}
		elseif($_REQUEST['action']=='detail')
		{
			$db_library_reading=M('db_library_reading');
			$where_detail['mid']=$_REQUEST['id'];
			$result=$db_library_reading->where($where_detail)->order('add_date desc')->select();
			foreach($result as $key=>$value)
			{
				$result[$key]['add_user']=$this->get_username($value['add_uid']);
			}
			echo json_encode($result);die;
		}
		elseif($_REQUEST['action']=='partner')
		{
			$db_library_partner=M('db_library_partner');
			$where['id']=$_REQUEST['id'];
			$result=$db_library_partner->where($where)->find();
			echo json_encode($result);die;
		}
		elseif($_REQUEST['action']=='partner_add')
		{
			$db_library_partner=M('db_library_partner');
			$where_add['m_id']=$_REQUEST['m_id'];
			$where_add['p_date']=$_REQUEST['p_date'];
			$where_add['content']=$_REQUEST['content'];
			$where_add['file_url']=$_REQUEST['file_url']?$_REQUEST['file_url']:NULL;
			$where_add['file_name']=$_REQUEST['file_name']?$_REQUEST['file_name']:NULL;
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_library_partner->add($where_add);
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='partner_edit')
		{
			$db_library_partner=M('db_library_partner');
			$result_d=$db_library_partner->where($where)->find();
			$where_save['id']=$_REQUEST['id'];
			$where_save['m_id']=$_REQUEST['m_id'];
			$where_save['p_date']=$_REQUEST['p_date'];
			$where_save['content']=$_REQUEST['content'];
			if(!empty($_REQUEST['file_name'])){
				$where_save['file_name']=$_REQUEST['file_name'];
				if($_REQUEST['file_url']){
					//判断是否修改过文件
					if($_REQUEST['file_url']!=$result_d['file_url']){
						$where_save['file_url']=$_REQUEST['file_url'];
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url']);
						if (file_exists($file1)){
							@unlink($file1);
						}
					}
				}else{
					$where_save['file_url']=NULL;
					if($result_d['file_url']){
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url']);
						if(file_exists($file1)){
							@unlink($file1);
						}
					}
				}
			}else{
				$where_save['file_name']=NULL;
				$where_save['file_url']=NULL;
				if($result_d['file_url']){
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url']);
					if(file_exists($file1)){
						@unlink($file1);
					}
				}
			}
			$result_bool=$db_library_partner->save($where_save);
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='partner_delete')
		{
			$db_library_partner=M('db_library_partner');
			//删除文件
			$result=$db_library_partner->where($where)->find();
			$file=str_replace("/dms_erp/uploads", "./uploads", $result['file_url']);
			if (file_exists($file)){
				@unlink($file);
			}
			//删除主单
			$result_bool=$db_library_partner->where($where)->delete();
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='talent_detail')
		{
			$db_library_main=M('db_library_main');
			$where['id']=$_REQUEST['id'];
			$result=$db_library_main->where($where)->find();
			echo json_encode($result);die;
		}
		elseif($_REQUEST['action']=='talent_edit')
		{
			$db_library_main=M('db_library_main');
			$where_save['id']=$_REQUEST['id'];
			$where_save['remark']=$_REQUEST['remark']?$_REQUEST['remark']:NULL;
			$result_bool=$db_library_main->save($where_save);
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='collection')
		{
			//收藏
			$db_library_reading=M('db_library_reading');
			$where_m['mid']=$_REQUEST['id'];
			$where_m['collection']=2;
			$where_m['add_uid']=$this->login_id;
			$has=$db_library_reading->where($where_m)->find();
			if(empty($has)){
				$where_m['add_date']=date("Y-m-d H:i:s");
				$db_library_reading->add($where_m);
			}else{
				$where_d['id']=$has['id'];
				$db_library_reading->where($where_d)->delete();
			}
			$data['status']=self::YES;
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='zd_top')
		{
			//置顶
			$db_library_main=M('db_library_main');
			$where_m['id']=$_REQUEST['id'];
			$where_m['section']=1;
			if(!empty($_REQUEST['home'])){$where_m['home']=1;}
			$where_m['zd_date']=date("Y-m-d H:i:s");
			$db_library_main->save($where_m);
			$data['status']=self::YES;
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='zd_down')
		{
			//取消置顶
			$db_library_main=M('db_library_main');
			$where_m['id']=$_REQUEST['id'];
			$where_m['section']=-1;
			$where_m['home']=-1;
			$where_m['zd_date']=NULL;
			$db_library_main->save($where_m);
			$data['status']=self::YES;
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='fx_top')
		{
			//分享
			$db_library_share=M('db_library_share');
			$db_library_share_starus=M('db_library_share_starus');
			$where_m['folder_type']=$_REQUEST['folder_type'];
			$where_m['mid']=$_REQUEST['id'];
			$where_m['add_uid']=$this->login_id;
			$have=$db_library_share->where($where_m)->find();
			if(empty($have)){
				$where_m['share_uids']=$_REQUEST['share_uids'];
				$where_m['share_date']=date("Y-m-d H:i:s");
				$where_m['add_date']=date("Y-m-d H:i:s");
				$id=$db_library_share->add($where_m);
				foreach(explode(',',$_REQUEST['share_uids']) as $key=>$value){
					$where_s['sid']=$id;
					$where_s['mid']=$_REQUEST['id'];
					$where_s['suid']=$value;
					$where_s['rstatus']=-1;
					$db_library_share_starus->add($where_s);
				}
				$data['status']=self::YES;
				echo json_encode($data);die;
			}else{
				$aa=explode(',',$_REQUEST['share_uids']);
				$bb=explode(',',$have['share_uids']);
				sort($aa);
				sort($bb);
				$re=join(',',$aa);
				$ha=join(',',$bb);
				if($re==$ha){
				}else{
					//主表
					$where_s['id']=$have['id'];
					$where_s['share_uids']=$re;
					$db_library_share->save($where_s);
					//副表
					foreach($aa as $ka=>$va){
						foreach($bb as $kb=>$vb){
							if($va==$vb){
								$yy[]=$va;
								unset($aa[$ka]);
								unset($bb[$kb]);
							}
						}
					}
					foreach($aa as $kaa=>$vaa){
						$where_a['sid']=$have['id'];
						$where_a['mid']=$have['mid'];
						$where_a['suid']=$vaa;
						$where_a['rstatus']=-1;
						$db_library_share_starus->add($where_a);
					}
					foreach($bb as $kbb=>$vbb){
						$where_b['sid']=$have['id'];
						$where_b['suid']=$vbb;
						$db_library_share_starus->where($where_b)->delete();
					}
				}
				$data['status']=self::YES;
				echo json_encode($data);die;
			}
		}
		elseif($_REQUEST['action']=='fx_down')
		{
			//取消分享
			$db_library_share=M('db_library_share');
			$db_library_share_starus=M('db_library_share_starus');
			$where_m['id']=$_REQUEST['id'];
			$dele=$db_library_share->where($where_m)->find();
			$db_library_share->where($where_m)->delete();
			$where_s['sid']=$dele['id'];
			$db_library_share_starus->where($where_s)->delete();
			$data['status']=self::YES;
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='types'){
			//消息 分享文件 已读未读
			$db_library_share_starus=M('db_library_share_starus');
			$where_s['sid']=$_REQUEST['id'];
			$where_s['rstatus']=$_REQUEST['types'];
			$data=$db_library_share_starus->where($where_s)->group('suid')->select();
			foreach($data as $key=>$val){
				$where_a['sid']=$_REQUEST['id'];
				$where_a['suid']=$val['suid'];
				$all=$db_library_share_starus->where($where_a)->count();
				$where_a['rstatus']=$_REQUEST['types'];
				$types=$db_library_share_starus->where($where_a)->count();
				if($all!=$types){
					unset($data[$key]);
				}else{
					$data[$key]['add_user']=$this->get_username($val['suid']);
				}
			}
			$data=array_values($data);
			if($_REQUEST['types']==-1){
				foreach($data as $ka=>$va){
					if($ka==0){
						$user=$va['add_user'];
					}else{
						$user.=','.$va['add_user'];
					}
				}
				echo json_encode($user);die;
			}else{
				echo json_encode($data);die;
			}
			
		}
	}
	
	//资料库-->详情 designed by:wangyitian 2017-08-31
	function library_detail(){
		if(!empty($_REQUEST['audit'])){$this->assign('audit',$_REQUEST['audit']);}
		$db_library_main=M('db_library_main');
		$where_find['db_library_main.id']=$_REQUEST['id'];
		if($_REQUEST['type']==1 || $_REQUEST['type']==2){
			$business=$db_library_main->field('db_audit_main.*,db_library_main.*,db_audit_main.id as mid')->join('db_audit_main on db_library_main.id=db_audit_main.audit_id')->where($where_find)->find();	
		}else{
			$business=$db_library_main->where($where_find)->find();
		}
		if($business['type']==5){
			$user=$this->get_user($business['name']);
			$business['name']=$user['username'];
			$business['center_name']=$this->get_oa_dep_name($user['center_id']);;
		}else{
			$db_universal_label1=M('db_universal_label1');
			foreach(explode(',',$business['center_id']) as $key=>$value){
				$name_center=$this->get_oa_dep_name($value);
				$str_name.=$name_center.',';
			}
			$business['center_name']=rtrim($str_name,',');
		}
		$type_name=$this->get_db_universal_type(5,1,NULL,NULL,$business['type']);
		$this->assign('type_name',$type_name['name2']);
		$this->assign('type_names',$type_name['name3']);
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['main_id']=$_REQUEST['id'];
		$detail=$db_universal_label_type->where($where_t)->select();
		$db_universal_label2=M('db_universal_label2');
		foreach($detail as $key=>$value)
		{
			$where_detail['first_id']=$value['first_id'];
			if(stripos($value['sort_id'],",")!==FALSE)
			{
				unset($name);
				foreach(explode(",",$value['sort_id']) as $kk=>$vv)
				{
					$where_detail['id']=$vv;
					$name[$kk]=$db_universal_label2->where($where_detail)->getField('second_name');
				}
				$business['types'][$key]=join(",",$name);
			}
			else
			{
				$where_detail['id']=$value['sort_id'];
				$business['types'][$key]=$db_universal_label2->where($where_detail)->getField('second_name');
			}
		}
		//swf文件是否存在
		$file_url=explode('.',$business['file_url']);
		$swf_url=$file_url[0].'.swf';
		$swf_url=str_replace("/dms_erp/uploads", "./uploads",$swf_url);
		if(file_exists($swf_url)) {
			$business['swfs']=1;
		}
		//音频文件是否存在
		if(!preg_match('/.pdf/',$business['file_url'])){
			$business['yp']=1;
		}
		//审核人员
		$audit_arr=$this->audit_user(6,$business['audit_type']);
		foreach($audit_arr as $kk=>$vv){
			if($business['status']>$vv['audit_sort']){
				switch($vv['audit_name']){
					case '审核人':
						$audit_arr[$kk]['audit_user']=$this->get_username($business['audit1_uid']);
						$audit_arr[$kk]['audit_date']=$business['audit1_date'];
						$audit_arr[$kk]['audit_comments']=$business['audit1_message'];
					break;
				}
			}
			if(empty($vv['audit_uid']) and empty($audit_arr[$kk]['audit_user'])){unset($audit_arr[$kk]);}
		}
		$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($business['post_uid'])."","audit_date"=>"".$business['post_date']."");
		array_unshift($audit_arr,$array2);
		$this->assign('audit_user',$audit_arr);
		$audit_sh=$this->audit_type_next_person(6,$business['audit_type'],$business['status'],'egt');
		$audit_qs=$this->audit_type_next_person(6,$business['audit_type'],$business['status'],'lt');
		if(in_array($this->login_id,explode(',',$audit_sh['audit_uid']))){$shenhe=1;}
		if(in_array($this->login_id,explode(',',$audit_qs['audit_uid']))){$qishen=1;}
		$this->assign('shenhe',$shenhe);
		$this->assign('qishen',$qishen);
		$this->assign('business',$business);
		//类别表
		$where_t['main_id']=$_REQUEST['id'];
		$where_t['type_id']=$_REQUEST['type'];
		$type=$db_universal_label_type->where($where_t)->select();
		$screen=$this->library_type_list($_REQUEST['classif'],NULL,NULL,1,$_REQUEST['center_id']);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				foreach($type as $k2=>$v2){
					$arr=explode(',',$v2['sort_id']);
					foreach($arr as $kk=>$vv){
						if($vv==$v1['id']){
							$screen[$key]['second'][$k1]['check']=1;
						}
					}
				}
			}
		}
		$this->assign('screen',$screen);
		//评论与回复
		$db_library_reply=M('db_library_reply');
		$where_comment['main_id']=$_REQUEST['id'];
		$where_comment['reply_id']=0;
		$reply=$db_library_reply->where($where_comment)->order('add_date')->select();
		foreach($reply as $key=>$value)
		{
			$reply[$key]['add_user']=$this->get_username($value['add_uid']);
			//回复
			$where_reply['reply_id']=$value['id'];
			$reply[$key]['answer']=$db_library_reply->where($where_reply)->find();
			if(!empty($reply[$key]['answer'])){$reply[$key]['answer']['add_user']=$this->get_username($reply[$key]['answer']['add_uid']);}
			//能否回复
			if(((is_permission('KJ',NULL,1)) and (empty($reply[$key]['answer']))) or ((is_permission('YW',NULL,1)) and (empty($reply[$key]['answer']))) or ((is_permission('BM',NULL,1)) and (empty($reply[$key]['answer']))) or ((is_permission('GY',NULL,1)) and (empty($reply[$key]['answer']))))
			{
				$reply[$key]['reply_able']=1;
			}
			//回复能否删除
			if(((is_permission('KJ',NULL,1)) and (!empty($reply[$key]['answer']))) or ((is_permission('YW',NULL,1)) and (!empty($reply[$key]['answer']))) or ((is_permission('BM',NULL,1)) and (!empty($reply[$key]['answer']))) or ((is_permission('GY',NULL,1)) and (!empty($reply[$key]['answer'])))) 
			{
				$reply[$key]['answer']['delete']=1;
			}
			//评论能否删除
			if((is_permission('KJ',NULL,1)) or (is_permission('YW',NULL,1)) or (is_permission('BM',NULL,1))  or (is_permission('GY',NULL,1)) or (($value['add_uid']==$this->login_id) and (empty($reply[$key]['answer']))))
			{
				$reply[$key]['delete']=1;
			}
		}
		$this->assign('reply',$reply);
		$db_library_partner=M('db_library_partner');
		$where['m_id']=$business['id'];
		$partner_list=$db_library_partner->where($where)->order('add_date desc')->select();
		foreach($partner_list as $key=>$value)
		{
			$partner_list[$key]['add_user']=$this->get_username($value['add_uid']);
		}
		$this->assign('partner_list',$partner_list);
		//已读操作
		$db_library_share=M('db_library_share');
		$db_library_share_starus=M('db_library_share_starus');
		$where_d['mid']=$_REQUEST['id'];
		$where_d['sid']=$_REQUEST['sid'];
		$where_d['suid']=$this->login_id;
		$ha=$db_library_share_starus->where($where_d)->find();
		if($ha['rstatus']==-1){
			$where_de['rstatus']=1;
			$where_de['add_uid']=$this->login_id;
			$where_de['add_date']=date('Y-m-d H:i:s');
			$db_library_share_starus->where($where_d)->save($where_de);
		}
		$a='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
		$b=$_SERVER['HTTP_REFERER'];
		if($a!=$b){
			unset($_SESSION['inde_more_url']);
			$_SESSION['inde_more_url']=$_SERVER['HTTP_REFERER'];
			if($_REQUEST['go']!=1){
				unset($_SESSION['inde_more_url']);
			}
		}
		if($_REQUEST['go']!=1){
			unset($_SESSION['inde_more_url']);
		}
		$this->display();
	}

	//资料库-->评论回复 designed by:wangyitian 2017-08-31
	function library_reply(){
		$db_library_reply=M('db_library_reply');
		if($_REQUEST['action']=='comment')
		{
			//评论
			$where_add['main_id']=$_REQUEST['main_id'];
			$where_add['reply_id']=0;
			$where_add['content']=$_REQUEST['content'];
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_library_reply->add($where_add);
		}	
		elseif($_REQUEST['action']=='reply')
		{
			//回复
			$where_add['main_id']=$_REQUEST['main_id'];
			$where_add['reply_id']=$_REQUEST['reply_id'];
			$where_add['content']=$_REQUEST['content'];
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_library_reply->add($where_add);
		}
		elseif($_REQUEST['action']=='delete_comment')
		{
			//删除回复
			$where_replys['reply_id']=$_REQUEST['id'];
			$reply=$db_library_reply->where($where_replys)->find();
			if(!empty($reply))
			{
				$where_delete_reply['id']=$reply['id'];
				$db_library_reply->where($where_delete_reply)->delete();
			}
			//删除评论
			$where_delete_comment['id']=$_REQUEST['id'];
			$result_bool=$db_library_reply->where($where_delete_comment)->delete();
		}
		elseif($_REQUEST['action']=='delete_reply')
		{
			//删除回复
			$where_delete['id']=$_REQUEST['id'];
			$result_bool=$db_library_reply->where($where_delete)->delete();
		}
		if($result_bool)
		{
			$data['status']=self::YES;
		}
		else
		{
			$data['status']=self::NO;
		}
		echo json_encode($data);die;
	}

	//资料库-->swf预览 designed by:zhangsen 2017-09-05
	function swf_list(){
		$db=M($_REQUEST ['db']);
		$where['id']=$_REQUEST ['id'];
		$result=$db->where($where)->find();
		$file_url=explode('.',$result['file_url']);
		$swf_url=$file_url[0].'.swf';
		$swf_url=str_replace("/dms_erp/uploads", "./uploads",$swf_url);
		$this->assign("swf",$swf_url);
		$this->display('Index/read_online');
	}
	
	//部门共享库 designed by:wangyitian 2017-08-31
	function department_list(){
		parent::check_permission('BM');
		//筛选
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		$ids_array=explode(',',$_REQUEST['ids']);
		$this->assign('ids',$_REQUEST['ids']);
		//功能显示判断
		$db_universal_type=M('db_universal_type');
		$where_cc['type']=10;
		$where_cc['name1']=3;
		$sz_status=$db_universal_type->where($where_cc)->find();
		$this->assign('sz_status',$sz_status);
		$db_universal_label_type=M('db_universal_label_type');
		//筛选判断
		$screen=$this->library_type_list(9,NULL,NULL,NULL,$center_id);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
			if($sz_status['name4']==1){
				//标签统计
				foreach($value['second'] as $kk=>$vv)
				{
					if($vv['second_name']!='全部')
					{
						$where_type['_string']='find_in_set("'.$vv['id'].'",sort_id)';
						$times=$db_universal_label_type->where($where_type)->count();
						$screen[$key]['second'][$kk]['times']=$times;
					}
				}
			}
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		//排序
		if(!empty($_REQUEST['action1'])){$action1=$_REQUEST['action1'];}
		$this->assign('action1',$action1);
		if(!empty($_REQUEST['action2'])){$action2=$_REQUEST['action2'];}
		$this->assign('action2',$action2);
		if(!empty($_REQUEST['action3'])){$action3=$_REQUEST['action3'];}elseif(empty($_REQUEST['action1']) and empty($_REQUEST['action2']) and empty($_REQUEST['action3'])){$action3='down';}
		$this->assign('action3',$action3);
		$db_library_main=M('db_library_main');
		$where['db_library_main.center_id']=$center_id;
		$where['db_library_main.type']=3;
		//排序
		if($action1=='up'){
			$order_str="pr.praisect";
		}elseif($action1=='down'){
			$order_str="pr.praisect desc";
		}
		if($action2=='up'){
			$order_str="py.replyct";
		}elseif($action2=='down'){
			$order_str="py.replyct desc";
		}
		if($action3=='up'){
			$order_str="db_library_main.add_date";
		}elseif($action3=='down'){
			$order_str="db_library_main.add_date desc";
		}
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if($vv['tid']!=$qb_id){
				$ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['tid'].'",sort_id))) and ';
			}
		}
		if(!empty($ids_str)){$where[]=rtrim($ids_str,'and ');}
		$count=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->select();
		$Page = new \Think\Page(count($count),C('PAGE_LIST_ROWS'));
		$show=$Page->show();
		$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->limit($Page->firstRow.','.$Page->listRows)->select();
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['type_id']=3;
		$db_universal_label2=M('db_universal_label2');
		foreach($result as $key=>$value)
		{
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['audit_user']=$this->get_username($value['audit_uid']);
			if(!empty($result[$key]))
			{
				$where_t['main_id']=$value['id'];
				$detail=$db_universal_label_type->where($where_t)->order('field(first_id,'.join(",",$first_sort).')')->select();
				foreach($detail as $kk=>$vv)
				{
					$where_detail['first_id']=$vv['first_id'];
					if(stripos($vv['sort_id'],",")!==FALSE)
					{
						unset($name);
						foreach(explode(",",$vv['sort_id']) as $kkk=>$vvv)
						{
							$where_detail['id']=$vvv;
							$name[$kkk]=$db_universal_label2->where($where_detail)->getField('second_name');
						}
						$result[$key]['types'][$kk]=join(",",$name);
					}
					else
					{
						$where_detail['id']=$vv['sort_id'];
						$result[$key]['types'][$kk]=$db_universal_label2->where($where_detail)->getField('second_name');
					}
				}
				$result[$key]['download_time']=$value['praisect'];
				$result[$key]['comment_num']=$value['replyct'];
			}
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		$this->display();
	}
	
	//部门共享库-->添加 designed by:wangyitian 2017-08-31
	function department_add(){
		parent::check_permission('BM',NULL,1);
		$this->assign('screen',$this->library_type_list(9,NULL,NULL,1,$_REQUEST['center_id']));
		$this->assign('center_id',$_REQUEST['center_id']);
		if($_REQUEST['action']=='add')
		{
			$db_library_main=M('db_library_main');
			$where_add['center_id']=$_REQUEST['center_id'];
			$where_add['name']=$_REQUEST['name'];
			$where_add['file_name']=$_REQUEST['file_name'];
			$where_add['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_add['remark']=$_REQUEST['remark'];}
			$where_add['type']=3;
			$where_add['add_uid']=$this->login_id;
			$where_add['add_date']=date("Y-m-d H:i:s");
			$id=$db_library_main->add($where_add);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$id;
			$where_t['type_id']=3;
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_t['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_t['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->add($where_t);
				}
			}
			$this->success("操作成功",__APP__."/Index/department_list/center_id/".$_REQUEST['center_id']);die;
		}
		$this->display();
	}
	
	//部门共享库-->编辑 designed by:wangyitian 2017-08-31
	function department_edit(){
		parent::check_permission('BM',NULL,1);
		//传值
		$this->assign('center_id',$_REQUEST['center_id']);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('ids',$_REQUEST['ids']);
		$this->assign('action1',$_REQUEST['action1']);
		$this->assign('action2',$_REQUEST['action2']);
		$this->assign('action3',$_REQUEST['action3']);
		//详情
		$db_library_main=M('db_library_main');
		$where_find['id']=$_REQUEST['id'];
		$business=$db_library_main->where($where_find)->find();
		$this->assign('business',$business);
		//类别表
		$db_universal_label_type=M('db_universal_label_type');
		$where_t['main_id']=$_REQUEST['id'];
		$where_t['type_id']=3;
		$type=$db_universal_label_type->where($where_t)->select();
		$screen=$this->library_type_list(9,NULL,NULL,1,$_REQUEST['center_id']);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				foreach($type as $k2=>$v2){
					$arr=explode(',',$v2['sort_id']);
					foreach($arr as $kk=>$vv){
						if($vv==$v1['id']){
							$screen[$key]['second'][$k1]['check']=1;
						}
					}
				}
			}
		}
		$this->assign('screen',$screen);
		if($_REQUEST['action']=='edit')
		{
			//判断是否修改过文件
			$file=$_REQUEST['file_url'];
			if($file!=$_REQUEST['file_url_old']){
				//删除原文件
				$file1=str_replace("/dms_erp/uploads", "./uploads", $_REQUEST['file_url_old']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$where_edit['id']=$_REQUEST['id'];
			$where_edit['name']=$_REQUEST['name'];
			$where_edit['file_name']=$_REQUEST['file_name'];
			$where_edit['file_url']=$_REQUEST['file_url'];
			if(!empty($_REQUEST['remark'])){$where_edit['remark']=$_REQUEST['remark'];}else{$where_edit['remark']=NULL;}
			$db_library_main->save($where_edit);
			//新增类别
			$db_universal_label2=M('db_universal_label2');
			$where_label2_add['add_uid']=$this->login_id;
			$where_label2_add['add_date']=date("Y-m-d H:i:s");
			//插入类别表
			$db_universal_label_type=M('db_universal_label_type');
			$where_t['main_id']=$_REQUEST['id'];
			$where_t['type_id']=3;
			$db_universal_label_type->where($where_t)->delete();
			foreach($_REQUEST as $key=>$value){
				if(strpos($key,'types')!==false){
					if(!empty($_REQUEST[$key]['name'])){
						//新增类别
						$where_label2_find['first_id']=$_REQUEST[$key]['first_id'];
						$sort=$db_universal_label2->where($where_label2_find)->order('second_sort desc')->getField('second_sort');
						$where_label2_add['second_sort']=$sort+1;
						$where_label2_add['first_id']=$_REQUEST[$key]['first_id'];
						$where_label2_add['second_name']=$_REQUEST[$key]['name'];
						//插入类别表
						$where_t['sort_id']=$db_universal_label2->add($where_label2_add);
					}else{
						$where_t['sort_id']=join(',',$_REQUEST[$key]['val']);
					}
					$where_t['first_id']=$_REQUEST[$key]['first_id'];
					$db_universal_label_type->add($where_t);
				}
			}
			$this->success("操作成功",__APP__."/Index/department_list/keyword/".$_REQUEST['keyword']."/center_id/".$_REQUEST['center_id']."/ids/".$_REQUEST['ids']."/action1/".$_REQUEST['action1']."/action2/".$_REQUEST['action2']."/action3/".$_REQUEST['action3']."&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//会议纪要 designed by:zhaoshihao 2017-10-17
	function meeting_minutes(){
		//赋值
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		$this->assign('login_center_id',$this->login_center_id);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$db_meeting_minutes=M('db_meeting_minutes');
		if(get_permission('HY',1)){
			if($center_id!=-10){$where['center_id']=$center_id;}
			if(get_permission('HY',NULL,2)){
				if($center_id!=-10){
					if($center_id==$this->login_center_id){
					}else{
						$where['db_meeting_minutes.status']=1;
					}
				}else{
					$where['_string']="(center_id=".$this->login_center_id.") or (db_meeting_minutes.status=1) ";
				}
			}elseif(get_permission('HY',NULL,3)){
				$where['_string']="(add_uid=".$this->login_id.") or (db_meeting_minutes.status=1)";
			}elseif(get_permission('HY',NULL,4)){
				$where['db_meeting_minutes.status']=1;
			}
		}elseif(get_permission('HY',2)){
			if(get_permission('HY',NULL,2)){
				if($center_id!=-10){
					if($center_id==$this->login_center_id){
						$where['_string']="((((db_meeting_minutes.status=-1) and ((center_id=".$center_id.") or (add_uid=".$this->login_id."))) or ((uid=".$this->login_id.") and (db_meeting_minutes.status=1))) and (center_id=".$center_id.")) or (center_id=".$center_id.")";
					}else{
						$where['_string']="(((db_meeting_minutes.status=-1) and (add_uid=".$this->login_id.")) or ((uid=".$this->login_id.") and (db_meeting_minutes.status=1))) and (center_id=".$center_id.")";
					}
				}else{
					$where['_string']="((db_meeting_minutes.status=-1) and ((center_id=".$this->login_center_id.") or (add_uid=".$this->login_id."))) or ((uid=".$this->login_id.") and (db_meeting_minutes.status=1)) or (center_id=".$this->login_center_id.")";
				}
			}elseif(get_permission('HY',NULL,3)){
				if($center_id!=-10){
					if($center_id==$this->login_center_id){
						$where['_string']="((((db_meeting_minutes.status=-1) and (add_uid=".$this->login_id.")) or ((uid=".$this->login_id.") and (db_meeting_minutes.status=1))) and (center_id=".$center_id.")) or (center_id=".$center_id.")";
					}else{
						$where['_string']="(((db_meeting_minutes.status=-1) and (add_uid=".$this->login_id.")) or ((uid=".$this->login_id.") and (db_meeting_minutes.status=1))) and (center_id=".$center_id.")";
					}
				}else{
					$where['_string']="((db_meeting_minutes.status=-1) and (add_uid=".$this->login_id.")) or ((uid=".$this->login_id.") and (db_meeting_minutes.status=1)) or (center_id=".$this->login_center_id.")";
				}
			}elseif(get_permission('HY',NULL,4)){
				if($center_id!=-10){
					if($center_id==$this->login_center_id){
						$where['_string']="(((uid=".$this->login_id.") and (db_meeting_minutes.status=1)) and (center_id=".$center_id.")) or (center_id=".$center_id.")";
					}else{
						$where['_string']="(uid=".$this->login_id.") and (db_meeting_minutes.status=1) and (center_id=".$center_id.")";
					}
				}else{
					$where['_string']="((uid=".$this->login_id.") and (db_meeting_minutes.status=1)) or (center_id=".$this->login_center_id.")";
				}
			}
		}elseif(get_permission('HY',3)){
			if($center_id!=-10){$where['center_id']=$center_id;}
			if(get_permission('HY',NULL,3)){
				$where['_string']="((db_meeting_minutes.status=-1) and (add_uid=".$this->login_id.")) or ((uid=".$this->login_id.") and (db_meeting_minutes.status=1))";
			}elseif(get_permission('HY',NULL,4)){
				$where['_string']="(uid=".$this->login_id.") and (db_meeting_minutes.status=1)";
			}
		}else{
			if($center_id!=-10){$where['center_id']=$center_id;}
			$where['uid']=$this->login_id;
			$where['db_meeting_minutes.status']=1;
		}
		$count=$db_meeting_minutes->where($where)->field('db_meeting_minutes.id')->join('left join db_meeting_minutes_detail on db_meeting_minutes.id=db_meeting_minutes_detail.mid')->group('db_meeting_minutes.id')->select();
		$Page = new \Think\Page(count($count),15);
		$show=$Page->show();
		$result=$db_meeting_minutes->field('db_meeting_minutes.*')->where($where)->join('left join db_meeting_minutes_detail on db_meeting_minutes.id=db_meeting_minutes_detail.mid')->limit($Page->firstRow.','.$Page->listRows)->order('db_meeting_minutes.id desc')->group('db_meeting_minutes.id')->select();
		//记录数
		$db_meeting_minutes_module=M('db_meeting_minutes_module');
		foreach($result as $key=>$value)
		{
			$where_m['id']=$value['mb_id'];
			$result[$key]['module']=$db_meeting_minutes_module->where($where_m)->find();
			//能否删除
			$where_d['hy_id']=$value['id'];
			$del=$db_meeting_minutes->where($where_d)->find();
			if(empty($del)){$result[$key]['del']=1;}
		}
		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->display();
	}
	
	//会议纪要-->添加 designed by:zhaoshihao 2017-10-17
	function meeting_minutes_add(){
		parent::check_permission('HY',NULL,1);
		//所属中心下拉菜单
		$this->assign('center_list',$this->get_oa_dep_list());
		$this->assign('center_name',$this->get_oa_dep_name($this->login_center_id));
		//会议模板
		$db_meeting_minutes_module=M('db_meeting_minutes_module');
		$where_m['center_id']=$this->login_center_id;
		$module=$db_meeting_minutes_module->where($where_m)->select();
		$this->assign('module',$module);
		//姓名下拉
		$this->assign('users',$this->get_all_username(1));
		//选择用户
		$this->assign("user_list",$this->get_all_department());
		if($_REQUEST['action']=='add'){
			$db_meeting_minutes=M('db_meeting_minutes');
			//主表
			$where['id']=$_REQUEST['mid'];
			$where['meeting_address']=$_REQUEST['meeting_address'];
			$where['date']=$_REQUEST['date'];
			$where['week']=date('W',strtotime($_REQUEST['date']));
			$where['year']=substr($_REQUEST['date'],0,4);
			$db_meeting_minutes->save($where);
			$this->success("操作成功",__APP__."/Index/meeting_minutes");die;
		}
		$this->display();
	}
	
	//会议纪要-->编辑 designed by:zhaoshihao 2017-10-17
	function meeting_minutes_edit(){
		parent::check_permission('HY',NULL,1);
		$db_meeting_minutes=M('db_meeting_minutes');
		$db_meeting_minutes_detail=M('db_meeting_minutes_detail');
		$db_meeting_minutes_module=M('db_meeting_minutes_module');
		//主表
		$where['id']=$_REQUEST['id'];
		$result=$db_meeting_minutes->where($where)->find();
		$result['center_name']=$this->get_oa_dep_name($result['center_id']);
		$where_h['id']=$result['hy_id'];
		$hy_id=$db_meeting_minutes->where($where_h)->find();
		$result['hy_num']=$hy_id['meeting_num'];
		$result['mb_name']=$hy_id['mb_name'];
		//副表
		$where_s['mid']=$_REQUEST['id'];
		$user=$db_meeting_minutes_detail->where($where_s)->select();
		$this->assign('user',$user);
		//与会人员
		$where_s['status']=1;
		$all=$db_meeting_minutes_detail->where($where_s)->select();
		foreach($all as $key=>$val){
			if($key==0){
				$uids=$val['uid'];
				$users=$this->get_username($val['uid']);
			}else{
				$uids.=','.$val['uid'];
				$users.=','.$this->get_username($val['uid']);
			}
		}
		$this->assign('uids',$uids);
		$this->assign('users',$users);
		//缺席人员
		$where_s['status']=-1;
		$nall=$db_meeting_minutes_detail->where($where_s)->select();
		if(!empty($nall)){
			foreach($nall as $kk=>$vv){
				$nall[$kk]['username']=$this->get_username($vv['uid']);
				$nall[$kk]['d_username']=$this->get_username($vv['d_uid']);
			}
			$this->assign('nall',$nall);
		}
		//会议呈报
		$where_de['mid']=$_REQUEST['id'];
		$where_de['_string']='(status=1) or ((status=-1) and (d_uid is not NULL))';
		$detail=$db_meeting_minutes_detail->where($where_de)->order('sort')->select();
		foreach($detail as $ka=>$va){
			$detail[$ka]['username']=$this->get_username($va['uid']);
			$detail[$ka]['d_username']=$this->get_username($va['d_uid']);
			$use=$this->get_user($va['uid']);
			$detail[$ka]['center_name']=$this->get_oa_dep_name($use['center_id']);
			$detail[$ka]['department_name']=$this->get_oa_dep_name($use['department_id']);
			$where_hy['mid']=$result['hy_id'];
			$where_hy['uid']=$va['uid'];
			$aasda=$db_meeting_minutes_detail->where($where_hy)->find();
			$detail[$ka]['matter_hy']=$aasda['matter'];
			$detail[$ka]['reply_hy']=$aasda['reply'];
			$detail[$ka]['ready_things_hy']=$aasda['ready_things'];
		}
		$this->assign('detail',$detail);
		//下拉人员
		$this->assign('userss',$this->get_all_username(1));
		//全部人员
		$where_mo['id']=$result['mb_id'];
		$module=$db_meeting_minutes_module->where($where_mo)->find();
		$user_list=$this->get_all_department($module['uids']);
		$this->assign('user_list',$user_list);
		$result['module_name']=$module['module_name'];
		$this->assign('result',$result);
		$this->assign('actio',$_REQUEST['actio']);
		if($_REQUEST['action']=='edit'){
			$db_meeting_minutes=M('db_meeting_minutes');
			//主表
			$where['id']=$_REQUEST['mid'];
			$where['meeting_address']=$_REQUEST['meeting_address'];
			$where['date']=$_REQUEST['date'];
			$where['week']=date('W',strtotime($_REQUEST['date']));
			$where['year']=substr($_REQUEST['date'],0,4);
			$db_meeting_minutes->save($where);
			$this->success("操作成功",__APP__."/Index/meeting_minutes/center/".$_REQUEST['center']."/&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//会议纪要-->详情 designed by:zhaoshihao 2017-10-17
	function meeting_minutes_detail(){
		$db_meeting_minutes=M('db_meeting_minutes');
		$db_meeting_minutes_detail=M('db_meeting_minutes_detail');
		$db_meeting_minutes_module=M('db_meeting_minutes_module');
		//主表
		$where['id']=$_REQUEST['id'];
		$result=$db_meeting_minutes->where($where)->find();
		$result['center_name']=$this->get_oa_dep_name($result['center_id']);
		$where_h['id']=$result['hy_id'];
		$hy_id=$db_meeting_minutes->where($where_h)->find();
		$result['hy_num']=$hy_id['meeting_num'];
		$result['mb_name']=$hy_id['mb_name'];
		//副表
		$where_s['mid']=$_REQUEST['id'];
		$user=$db_meeting_minutes_detail->where($where_s)->select();
		$this->assign('user',$user);
		//与会人员
		$where_s['status']=1;
		$all=$db_meeting_minutes_detail->where($where_s)->select();
		foreach($all as $key=>$val){
			if($key==0){
				$uids=$val['uid'];
				$users=$this->get_username($val['uid']);
			}else{
				$uids.=','.$val['uid'];
				$users.=','.$this->get_username($val['uid']);
			}
		}
		$this->assign('uids',$uids);
		$this->assign('users',$users);
		//缺席人员
		$where_s['status']=-1;
		$nall=$db_meeting_minutes_detail->where($where_s)->select();
		foreach($nall as $kk=>$vv){
			$nall[$kk]['username']=$this->get_username($vv['uid']);
			$nall[$kk]['d_username']=$this->get_username($vv['d_uid']);
		}
		$this->assign('nall',$nall);
		//会议呈报
		$where_de['db_meeting_minutes_detail.mid']=$_REQUEST['id'];
		$map['db_meeting_minutes_detail.matter']=array('exp','is not NULL');
		$map['db_meeting_minutes_detail.reply']=array('exp','is not NULL');
		$map['db_meeting_minutes_detail.ready_things']=array('exp','is not NULL');
		$map['_logic']='or';
		$where_de['_complex']=$map;
		$where_de['_string']='(db_meeting_minutes_detail.status=1) or ((db_meeting_minutes_detail.status=-1) and (db_meeting_minutes_detail.d_uid is not NULL))';
		$detail=$db_meeting_minutes_detail->field('db_user.center_id')->where($where_de)->join('left join db_user on db_meeting_minutes_detail.uid=db_user.id')->order('sort')->group('db_user.center_id')->select();
		foreach($detail as $ka=>$va){
			$where_de['center_id']=$va['center_id'];
			$detail[$ka]['detail']=$db_meeting_minutes_detail->field('db_meeting_minutes_detail.*')->where($where_de)->join('left join db_user on db_meeting_minutes_detail.uid=db_user.id')->order('sort')->select();
			foreach($detail[$ka]['detail'] as $k1=>$v1){
				if(!empty($hy_id)){
					$where_gl['mid']=$hy_id['id'];
					$where_gl['uid']=$v1['uid'];
					$gl=$db_meeting_minutes_detail->where($where_gl)->find();
					$detail[$ka]['detail'][$k1]['matter_gl']=$gl['matter'];
					$detail[$ka]['detail'][$k1]['reply_gl']=$gl['reply'];
					$detail[$ka]['detail'][$k1]['ready_things_gl']=$gl['ready_things'];
				}
				$detail[$ka]['detail'][$k1]['username']=$this->get_username($v1['uid']);
				$detail[$ka]['detail'][$k1]['d_username']=$this->get_username($v1['d_uid']);
				$detail[$ka]['sum']+=1;
				if(!empty($v1['matter'])){$detail[$ka]['sum']+=1;}
				if(!empty($v1['reply'])){$detail[$ka]['sum']+=1;}
				if(!empty($v1['ready_things'])){$detail[$ka]['sum']+=1;}
			}
			$detail[$ka]['center_name']=$this->get_oa_dep_name($va['center_id']);
			
		}
		$this->assign('detail',$detail);
		//下拉人员
		$this->assign('userss',$this->get_all_username(1));
		//全部人员
		$where_mo['id']=$result['mb_id'];
		$module=$db_meeting_minutes_module->where($where_mo)->find();
		$user_list=$this->get_all_department($module['uids']);
		$this->assign('user_list',$user_list);
		$result['module_name']=$module['module_name'];
		$this->assign('result',$result);
		$this->display();
	}
	
	//会议纪要-->ajax designed by:zhaoshihao 2017-10-17
	function meeting_minutes_ajax(){
		if($_REQUEST['action']=='main_add'){
			//点击生成与会人员
			$db_meeting_minutes_module=M('db_meeting_minutes_module');
			$where_s['id']=$_REQUEST['mb_id'];
			$user_list=$db_meeting_minutes_module->where($where_s)->find();
			$db_meeting_minutes=M('db_meeting_minutes');
			$where['mb_id']=$_REQUEST['mb_id'];
			if($_REQUEST['hy_id']!=-10){$where['hy_id']=$_REQUEST['hy_id'];}
			$where['mb_name']=$user_list['module_name'];
			$nums=$db_meeting_minutes->order('id desc')->find();
			if(empty($nums))
			{
				$num='0001';
			}
			else
			{
				$num=substr($nums['meeting_num'],2,4)+1;
				if(strlen($num)==1){$num='000'.$num;}
				elseif(strlen($num)==2){$num='00'.$num;}
				elseif(strlen($num)==3){$num='0'.$num;}
			}
			$where['meeting_num']='HY'.$num;
			$where['meeting_address']=$_REQUEST['meeting_address'];
			$where['date']=$_REQUEST['date'];
			$where['week']=date('W',strtotime($_REQUEST['date']));
			$where['year']=substr($_REQUEST['date'],0,4);
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$where['status']=-1;
			if(get_permission('HY',NULL,1)){
				$where['center_id']=$_REQUEST['center_id'];
			}else{
				$where['center_id']=$this->login_center_id;
			}
			$result_bool=$db_meeting_minutes->add($where);
			$data['user_list']=$this->get_all_department($user_list['uids']);
			$data['mid']=$result_bool;
		}elseif($_REQUEST['action']=='users'){
			//确认用户
			$db_meeting_minutes_detail=M('db_meeting_minutes_detail');
			$db_meeting_minutes=M('db_meeting_minutes');
			$db_meeting_minutes_module=M('db_meeting_minutes_module');
			$where_f['id']=$_REQUEST['mid'];
			$result=$db_meeting_minutes->where($where_f)->find();
			$where_m['id']=$result['mb_id'];
			$module=$db_meeting_minutes_module->where($where_m)->find();
			$where_d['mid']=$_REQUEST['mid'];
			$detai=$db_meeting_minutes_detail->where($where_d)->find();
			$arr=array();
			$ar1=explode(',',$module['uids']);
			$ar2=explode(',',$_REQUEST['uids']);
			foreach($ar1 as $k1=>$v1){
				foreach($ar2 as $k2=>$v2){
					if($v2==$v1){
						$arr[]=$v1;
						unset($ar1[$k1]);
					}
				}
			}
			$where_s['mid']=$_REQUEST['mid'];
			foreach($arr as $key=>$val){
				$arrn[]=$this->get_username($val);
				$where_s['uid']=$val;
				if(empty($detai)){
					$where_s['status']=1;
					$db_meeting_minutes_detail->add($where_s);
				}else{
					$where_ss['status']=1;
					$where_ss['d_uid']=NULL;
					$db_meeting_minutes_detail->where($where_s)->save($where_ss);
				}
			}
			$where_s1['mid']=$_REQUEST['mid'];
			$i=0;
			foreach($ar1 as $kk=>$vv){
				$nall[$i]['id']=$vv;
				$nall[$i]['username']=$this->get_username($vv);
				$ar1n[]=$this->get_username($vv);
				$where_s1['uid']=$vv;
				if(empty($detai)){
					$where_s1['status']=-1;
					$db_meeting_minutes_detail->add($where_s1);
				}else{
					$where_ss1['status']=-1;
					$where_ss1['d_uid']=NULL;
					$db_meeting_minutes_detail->where($where_s1)->save($where_ss1);
				}
				$i++;
			}
			$data['cuid']=$arr;
			$data['cuser']=$arrn;
			$data['cusers']=$this->get_username(join(",",$arr));
			$data['ncuid']=$ar1;
			$data['ncuser']=$ar1n;
			$data['ncusers']=$this->get_username(join(",",$ar1));
			$data['nall']=$nall;
			$data['user_list']=$this->get_all_department($module['uids']);
			$data['users']=$this->get_all_username(1);
			$where_de['mid']=$_REQUEST['mid'];
			$sort=$db_meeting_minutes_detail->where($where_de)->order('sort')->select();
			$i=1;
			foreach(explode(',',$module['uids']) as $ka=>$va){
				foreach($sort as $kkk=>$vvv){
					if($va==$vvv['uid']){
						$where_add['id']=$vvv['id'];
						$where_add['sort']=$i;
						$db_meeting_minutes_detail->save($where_add);
						$i++;
					}
				}
			}
			$where_de['_string']='(status=1) or ((status=-1) and (d_uid is not NULL))';
			$detail=$db_meeting_minutes_detail->where($where_de)->order('sort')->select();
			foreach($detail as $ka=>$va){
				$detail[$ka]['username']=$this->get_username($va['uid']);
				$detail[$ka]['d_username']=$this->get_username($va['d_uid']);
				$use=$this->get_user($va['uid']);
				$detail[$ka]['center_name']=$this->get_oa_dep_name($use['center_id']);
				$detail[$ka]['department_name']=$this->get_oa_dep_name($use['department_id']);
				$where_hy['mid']=$result['hy_id'];
				$where_hy['uid']=$va['uid'];
				$aasda=$db_meeting_minutes_detail->where($where_hy)->find();
				$detail[$ka]['matter_hy']=$aasda['matter'];
				$detail[$ka]['reply_hy']=$aasda['reply'];
				$detail[$ka]['ready_things_hy']=$aasda['ready_things'];
			}
			$data['detail']=$detail;
			$where_n['mid']=$_REQUEST['mid'];
			$where_n['status']=-1;
			$data['nchoose']=$db_meeting_minutes_detail->where($where_n)->order('sort')->select();
			$where_n['status']=1;
			$data['choose']=$db_meeting_minutes_detail->where($where_n)->order('sort')->select();
		}elseif($_REQUEST['action']=='user_add'){
			//备注缺席
			$db_meeting_minutes_detail=M('db_meeting_minutes_detail');
			$db_meeting_minutes=M('db_meeting_minutes');
			$result=$db_meeting_minutes->where('id='.$_REQUEST['mid'].'')->find();
			$where['mid']=$_REQUEST['mid'];
			$where['uid']=$_REQUEST['uid'];
			if($_REQUEST['d_uid']!=-10){$where_s['d_uid']=$_REQUEST['d_uid'];}else{$where_s['d_uid']=NULL;}
			$db_meeting_minutes_detail->where($where)->save($where_s);
			$where_f['mid']=$_REQUEST['mid'];
			$where_f['_string']='(status=1) or ((status=-1) and (d_uid is not NULL))';
			$detail=$db_meeting_minutes_detail->where($where_f)->order('sort')->select();
			foreach($detail as $ka=>$va){
				$detail[$ka]['username']=$this->get_username($va['uid']);
				$detail[$ka]['d_username']=$this->get_username($va['d_uid']);
				$use=$this->get_user($va['uid']);
				$detail[$ka]['center_name']=$this->get_oa_dep_name($use['center_id']);
				$detail[$ka]['department_name']=$this->get_oa_dep_name($use['department_id']);
				$where_hy['mid']=$result['hy_id'];
				$where_hy['uid']=$va['uid'];
				$aasda=$db_meeting_minutes_detail->where($where_hy)->find();
				$detail[$ka]['matter_hy']=$aasda['matter'];
				$detail[$ka]['reply_hy']=$aasda['reply'];
				$detail[$ka]['ready_things_hy']=$aasda['ready_things'];
			}
			$data['detail']=$detail;
		}elseif($_REQUEST['action']=='message'){
			//实时添加内容
			$db_meeting_minutes_detail=M('db_meeting_minutes_detail');
			$where['id']=$_REQUEST['id'];
			if($_REQUEST['dataid']==1){
				$where['matter']=$_REQUEST['val'];
			}elseif($_REQUEST['dataid']==2){
				$where['reply']=$_REQUEST['val'];
			}elseif($_REQUEST['dataid']==3){
				$where['ready_things']=$_REQUEST['val'];
			}
			$db_meeting_minutes_detail->save($where);
		}elseif($_REQUEST['action']=='num'){
			//编号,关联会议下拉
			$db_meeting_minutes=M('db_meeting_minutes');
			$nums=$db_meeting_minutes->order('id desc')->find();
			if(empty($nums))
			{
				$num='0001';
			}
			else
			{
				$num=substr($nums['meeting_num'],2,4)+1;
				if(strlen($num)==1){$num='000'.$num;}
				elseif(strlen($num)==2){$num='00'.$num;}
				elseif(strlen($num)==3){$num='0'.$num;}
			}
			$data['num']='HY'.$num;
			$where['mb_id']=$_REQUEST['mid'];
			$data['hy']=$db_meeting_minutes->where($where)->select();
		}elseif($_REQUEST['action']=='center'){
			//会议模板
			$db_meeting_minutes_module=M('db_meeting_minutes_module');
			$where['center_id']=$_REQUEST['center_id'];
			$module=$db_meeting_minutes_module->where($where)->select();
			$data['module']=$module;
		}elseif($_REQUEST['action']=='delete'){
			$db_meeting_minutes=M('db_meeting_minutes');
			$db_meeting_minutes_detail=M('db_meeting_minutes_detail');
			$where_m['mid']=$_REQUEST['mid'];
			$db_meeting_minutes_detail->where($where_m)->delete();
			$where['id']=$_REQUEST['mid'];
			$db_meeting_minutes->where($where)->delete();
		}elseif($_REQUEST['action']=='audit'){
			$db_meeting_minutes=M('db_meeting_minutes');
			$where['id']=$_REQUEST['mid'];
			$where['status']=1;
			$db_meeting_minutes->save($where);
		}elseif($_REQUEST['action']=='remove'){
			$db_meeting_minutes=M('db_meeting_minutes');
			$where['id']=$_REQUEST['mid'];
			$where['status']=-1;
			$db_meeting_minutes->save($where);
		}
		$data['status']=self::YES;
		$data['msg']='操作成功';
		echo json_encode($data);die;
	}
	
	//会议纪要-->会议模块 designed by:zhaoshihao 2017-10-17
	function meeting_minutes_module(){
		parent::check_permission('HY',NULL,1);
		//赋值
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		$db_meeting_minutes_module=M('db_meeting_minutes_module');
		if(get_permission('HY',3)){
			$where['add_uid']=$this->login_id;
		}elseif(get_permission('HY',2)){
			$where['center_id']=$this->login_center_id;
		}if(get_permission('HY',1)){
			if($center_id!=-10){$where['center_id']=$center_id;}
		}
		$result=$db_meeting_minutes_module->where($where)->select();
		$db_meeting_minutes=M('db_meeting_minutes');
		foreach($result as $key=>$value){
			$result[$key]['users']=$this->get_username($value['uids']);
			$result[$key]['center_name']=$this->get_oa_dep_name($value['center_id']);
			$where_d['mb_id']=$value['id'];
			$del=$db_meeting_minutes->where($where_d)->find();
			if(empty($del)){$result[$key]['delete']=1;}
		}
		$this->assign('result',$result);
		$this->display();
	}
	
	//会议纪要-->会议模块-->添加 designed by:zhaoshihao 2017-10-17
	function meeting_minutes_module_add(){
		parent::check_permission('HY',NULL,1);
		//所属中心下拉菜单
		$this->assign('center_list',$this->get_oa_dep_list());
		$this->assign("user_list",$this->get_all_department());
		$db_meeting_minutes_module=M('db_meeting_minutes_module');
		$module=$db_meeting_minutes_module->select();
		$this->assign('module',$module);
		if($_REQUEST['action']=='add'){
			$where_m['module_name']=$_REQUEST['module_name'];
			$mod=$db_meeting_minutes_module->where($where_m)->find();
			if(!empty($mod)){
				$this->error('该会议模块已存在，请重新填写');die;
			}
			if(get_permission('HY',NULL,1)){
				$where_s['center_id']=$_REQUEST['center_id'];
			}else{
				$where_s['center_id']=$this->login_center_id;
			}
			$where_s['module_name']=$_REQUEST['module_name'];
			$where_s['uids']=$_REQUEST['uids'];
			$where_s['add_uid']=$this->login_id;
			$where_s['add_date']=date('Y-m-d H:i:s');
			$db_meeting_minutes_module->add($where_s);
			$this->success("操作成功",__APP__."/Index/meeting_minutes_module");die;
		}
		$this->display();
	}
	
	//会议纪要-->会议模块-->编辑 designed by:zhaoshihao 2017-10-17
	function meeting_minutes_module_edit(){
		parent::check_permission('HY',NULL,1);
		//所属中心下拉菜单
		$this->assign('center_list',$this->get_oa_dep_list());
		$db_meeting_minutes_module=M('db_meeting_minutes_module');
		$db_meeting_minutes=M('db_meeting_minutes');
		$this->assign("user_list",$this->get_all_department());
		$where['id']=$_REQUEST['id'];
		$result=$db_meeting_minutes_module->where($where)->find();
		$result['users']=$this->get_username($result['uids']);
		$result['center_name']=$this->get_oa_dep_name($result['center_id']);
		//能否编辑中心
		$where_d['mb_id']=$result['id'];
		$del=$db_meeting_minutes->where($where_d)->find();
		if(empty($del)){$result['edit']=1;}
		$this->assign('result',$result);
		$where_m['id']=array('not in',$_REQUEST['id']);
		$module=$db_meeting_minutes_module->where($where_m)->select();
		$this->assign('module',$module);
		$this->assign('center_ids',$_REQUEST['center_ids']);
		if($_REQUEST['action']=='edit'){
			
			$where_ma['id']=array('not in',$_REQUEST['id']);
			$where_ma['module_name']=$_REQUEST['module_name'];
			$mod=$db_meeting_minutes_module->where($where_ma)->find();
			if(!empty($mod)){
				$this->error('该会议模块已存在，请重新填写');die;
			}
			if(!empty($_REQUEST['center_id'])){
				$where_s['center_id']=$_REQUEST['center_id'];
			}
			$where_s['id']=$_REQUEST['id'];
			$where_s['module_name']=$_REQUEST['module_name'];
			$where_s['uids']=$_REQUEST['uids'];
			$db_meeting_minutes_module->save($where_s);
			$this->success("操作成功",__APP__."/Index/meeting_minutes_module/center_id/".$_REQUEST['center_ids']);die;
		}
		$this->display();
	}
	
	//会议纪要-->会议模块-->操作 designed by:zhaoshihao 2017-10-17
	function meeting_minutes_module_audit(){
		if($_REQUEST['action']=='delete'){
			$db_meeting_minutes_module=M('db_meeting_minutes_module');
			$db_meeting_minutes=M('db_meeting_minutes');
			$where_d['mb_id']=$_REQUEST['id'];
			$del=$db_meeting_minutes->where($where_d)->find();
			if(empty($del)){
				$where['id']=$_REQUEST['id'];
				$result_bool=$db_meeting_minutes_module->where($where)->delete();
			}
		}elseif($_REQUEST['action']=='edit'){
			$db_meeting_minutes_module=M('db_meeting_minutes_module');
			$where['id']=$_REQUEST['id'];
			$where['uids']=join(",",$_REQUEST['uids']);
			$db_meeting_minutes_module->save($where);
			$where_s['id']=$_REQUEST['id'];
			$detail=$db_meeting_minutes_module->where($where_s)->find();
			$data['uids']=$detail['uids'];
			$data['users']=$this->get_username($detail['uids']);
		}
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	
	//协作申请表 designed by:zhaoshihao 2017-11-07
	function assist_apply(){
		$db_audit_main=M('db_audit_main');
		$where['db_audit_main.add_uid']=$this->login_id;
		$where['db_audit_main.type']=1;
		$count=$db_audit_main->where($where)->count();
		$Page = new \Think\Page($count,15);
		$show=$Page->show();
		$result=$db_audit_main->field('db_audit_main.*,work_nature,demand_depart,main_demand')->where($where)->join('left join db_assist_apply on db_audit_main.id=db_assist_apply.mid')->order('db_audit_main.id desc')->limit($Page->firstRow.','.$Page->listRows)->group('db_audit_main.id')->select();
		$db_assist_apply=M('db_assist_apply');
		foreach($result as $key=>$value){
			$work_nature=array();
			$demand_depart=array();
			$project=parent::get_project($value['pid']);
			$result[$key]['project_num']=$project['project_num'];
			$result[$key]['project_name']=$project['project_name'];
			$result[$key]['manager_name']=$project['manager_name'];
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['dh_user']=$this->get_username($value['dh_uid']);
			foreach(explode(",",$value['work_nature']) as $k1=>$v1){
				$work_nature[]=$this->get_db_universal_label(2,$v1);
			}
			$result[$key]['work_nature']=join(',',$work_nature);
			foreach(explode(",",$value['demand_depart']) as $k2=>$v2){
				$demand_depart[]=$this->get_db_universal_label(2,$v2);
			}
			$result[$key]['demand_depart']=join(',',$demand_depart);
		}
		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->display();
	}
	
	//协作申请表-->添加 designed by:zhaoshihao 2017-11-07
	function assist_apply_add(){
		$user=$this->get_user($this->login_id);
		$user['department_name']=$this->get_db_universal_label(2,$user['department_id']);
		$this->assign('user',$user);
		$this->assign('screen',$this->library_type_list(13,NULL,NULL,1));
		//所有项目
		$project=array();
		$db_project=M('db_project');
		$where_p['_string']="(manager_uid=".$this->login_id.") or (director_uid=".$this->login_id.")";
		$where_p['status']=1;
		$pro=$db_project->where($where_p)->group('id')->select();
		foreach($pro as $ka=>$va){
			$project[]=$va['id'];
		}
		$db_project_bg=M('db_project_bg');
		$where_bg['_string']='find_in_set("'.$this->login_id.'",project_uids)';
		$where_bg['status']=1;
		$bg=$db_project->field('db_project.*')->join('left join db_project_bg on db_project.id=db_project_bg.pid')->where($where_bg)->select();
		foreach($bg as $ka=>$va){
			$project[]=$va['id'];
		}
		$db_project_user=M('db_project_user');
		$where_u['uid']=$this->login_id;
		$where_u['pid']=array('exp','is not NULL');
		$where_u['_string']="(('".date("Y-m-d")."'>=come_date and '".date("Y-m-d")."'<`out_date`) or ('".date("Y-m-d")."'>=come_date and out_date is NULL))";
		$puser=$db_project_user->where($where_u)->group('pid')->select();
		foreach($puser as $ka=>$va){
			$project[]=$va['pid'];
		}
		$project=array_unique($project);
		rsort($project);
		$where_ps['id']=array('in',join(',',$project));
		$where_ps['status']=1;
		if($this->login_id==1){unset($where_ps);$where_ps['status']=1;}
		$project_list=$db_project->where($where_ps)->order('id desc')->select();
		$this->assign('project_list',$project_list);
		//添加
		if($_REQUEST['action']=='doadd'){
			//
			$db_audit_main=M('db_audit_main');
			$field='XZ';
			$where_s['type']=1;
			$where_s['order_number']=array('like',$field.date('Ymd').'%');
			$result=$db_audit_main->field('order_number')->where($where_s)->order('order_number desc')->find();
			if(empty($result))
			{
				$item=$field.date('Ymd').'001';
			}
			else
			{
				$item=$field.(substr($result['order_number'],2)+1);
			}
			$where_au['pid']=$_REQUEST['pid'];
			$where_au['order_number']=$item;
			$pd=$this->get_project($_REQUEST['pid']);
			$where_au['audit_type']=$pd['center_id'];
			$where_au['status']=-1;
			$where_au['type']=1;
			$where_au['add_uid']=$this->login_id;
			$where_au['add_date']=date('Y-m-d H:i:s');
			$id=$db_audit_main->add($where_au);
			//
			$db_assist_apply=M('db_assist_apply');
			array_shift($_REQUEST['file_name']);
			array_shift($_REQUEST['file_url']);
			if(empty($_REQUEST['file_name'])){
				$where['mid']=$id;
				foreach($_REQUEST as $key=>$value){
					if(strpos($key,'types')!==false){
						if($_REQUEST[$key]['first_id']=='51'){
							$where['work_nature']=join(',',$_REQUEST[$key]['val']);
						}else{
							$where['demand_depart']=join(',',$_REQUEST[$key]['val']);
						}
					}
				}
				$where['main_demand']=$_REQUEST['text_hid'];
				$where['add_uid']=$this->login_id;
				$where['add_date']=date('Y-m-d H:i:s');
				$db_assist_apply->add($where);
			}else{
				foreach($_REQUEST['file_name'] as $kk=>$vv)
				{
					$where['mid']=$id;
					foreach($_REQUEST as $key=>$value){
						if(strpos($key,'types')!==false){
							if($_REQUEST[$key]['first_id']=='51'){
								$where['work_nature']=join(',',$_REQUEST[$key]['val']);
							}else{
								$where['demand_depart']=join(',',$_REQUEST[$key]['val']);
							}
						}
					}
					$where['main_demand']=$_REQUEST['text_hid'];
					$where['add_uid']=$this->login_id;
					$where['add_date']=date('Y-m-d H:i:s');
					$where['file_name']=$vv;
					$where['file_url']=$_REQUEST['file_url'][$kk];
					$db_assist_apply->add($where);
				}
			}
			$this->success("操作成功",__APP__."/Index/assist_apply");die;
		}
		$this->display();
	}
	
	//协作申请表-->编辑 designed by:zhaoshihao 2017-11-07
	function assist_apply_edit(){
		//人员
		$user=$this->get_user($this->login_id);
		$user['department_name']=$this->get_db_universal_label(2,$user['department_id']);
		$this->assign('user',$user);
		//详情
		$db_audit_main=M('db_audit_main');
		$where_find['db_audit_main.id']=$_REQUEST['id'];
		$result=$db_audit_main->where($where_find)->field('db_audit_main.*,work_nature,demand_depart,main_demand')->join('left join db_assist_apply on db_audit_main.id=db_assist_apply.mid')->find();
		$this->assign('result',$result);
		$db_assist_apply=M('db_assist_apply');
		$where_de['mid']=$_REQUEST['id'];
		$detail=$db_assist_apply->where($where_de)->select();
		$this->assign('detail',$detail);
		//类别表
		$screen=$this->library_type_list(13,NULL,NULL,1);
		foreach($screen as $key=>$value){
			foreach($value['second'] as $k1=>$v1){
				$arr1=explode(',',$result['work_nature']);
				foreach($arr1 as $kk=>$vv){
					if($vv==$v1['id']){
						$screen[$key]['second'][$k1]['check']=1;
					}
				}
				$arr2=explode(',',$result['demand_depart']);
				foreach($arr2 as $kkk=>$vvv){
					if($vvv==$v1['id']){
						$screen[$key]['second'][$k1]['check']=1;
					}
				}
			}
		}
		$this->assign('screen',$screen);
		//所有项目
		$project=array();
		$db_project=M('db_project');
		$where_p['_string']="(manager_uid=".$this->login_id.") or (director_uid=".$this->login_id.")";
		$where_p['status']=1;
		$pro=$db_project->where($where_p)->group('id')->select();
		foreach($pro as $ka=>$va){
			$project[]=$va['id'];
		}
		$db_project_bg=M('db_project_bg');
		$where_bg['_string']='find_in_set("'.$this->login_id.'",project_uids)';
		$where_bg['status']=1;
		$bg=$db_project->field('db_project.*')->join('left join db_project_bg on db_project.id=db_project_bg.pid')->where($where_bg)->select();
		foreach($bg as $ka=>$va){
			$project[]=$va['id'];
		}
		$db_project_user=M('db_project_user');
		$where_u['uid']=$this->login_id;
		$where_u['pid']=array('exp','is not NULL');
		$where_u['_string']="(('".date("Y-m-d")."'>=come_date and '".date("Y-m-d")."'<`out_date`) or ('".date("Y-m-d")."'>=come_date and out_date is NULL))";
		$puser=$db_project_user->where($where_u)->group('pid')->select();
		foreach($puser as $ka=>$va){
			$project[]=$va['pid'];
		}
		$project=array_unique($project);
		rsort($project);
		$where_ps['id']=array('in',join(',',$project));
		$where_ps['status']=1;
		if($this->login_id==1){unset($where_ps);$where_ps['status']=1;}
		$project_list=$db_project->where($where_ps)->order('id desc')->select();
		$this->assign('project_list',$project_list);
		//编辑
		if($_REQUEST['action']=='doedit'){
			//
			$where_au['id']=$_REQUEST['id'];
			$where_au['pid']=$_REQUEST['pid'];
			$pd=$this->get_project($_REQUEST['pid']);
			$where_au['audit_type']=$pd['center_id'];
			$where_au['status']=-1;
			$where_au['type']=1;
			$where_au['add_uid']=$this->login_id;
			$where_au['add_date']=date('Y-m-d H:i:s');
			$db_audit_main->save($where_au);
			//
			$db_assist_apply=M('db_assist_apply');
			$where_d['mid']=$_REQUEST['id'];
			$file_list=$db_assist_apply->where($where_d)->select();
			foreach($file_list as $kc=>$vc)
			{
				$file1=str_replace("/dms_erp/uploads", "./uploads", $vc['file_url']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$db_assist_apply->where($where_d)->delete();
			//
			array_shift($_REQUEST['file_name']);
			array_shift($_REQUEST['file_url']);
			if(empty($_REQUEST['file_name'])){
				$where['mid']=$_REQUEST['id'];
				foreach($_REQUEST as $key=>$value){
					if(strpos($key,'types')!==false){
						if($_REQUEST[$key]['first_id']=='51'){
							$where['work_nature']=join(',',$_REQUEST[$key]['val']);
						}else{
							$where['demand_depart']=join(',',$_REQUEST[$key]['val']);
						}
					}
				}
				$where['main_demand']=$_REQUEST['text_hid'];
				$where['add_uid']=$this->login_id;
				$where['add_date']=date('Y-m-d H:i:s');
				$db_assist_apply->add($where);
			}else{
				foreach($_REQUEST['file_name'] as $kk=>$vv)
				{
					$where['mid']=$_REQUEST['id'];
					foreach($_REQUEST as $key=>$value){
						if(strpos($key,'types')!==false){
							if($_REQUEST[$key]['first_id']=='51'){
								$where['work_nature']=join(',',$_REQUEST[$key]['val']);
							}else{
								$where['demand_depart']=join(',',$_REQUEST[$key]['val']);
							}
						}
					}
					$where['main_demand']=$_REQUEST['text_hid'];
					$where['add_uid']=$this->login_id;
					$where['add_date']=date('Y-m-d H:i:s');
					$where['file_name']=$vv;
					$where['file_url']=$_REQUEST['file_url'][$kk];
					$db_assist_apply->add($where);
				}
			}
			$this->success("操作成功",__APP__."/Index/assist_apply/&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//协作申请表-->详情 designed by:zhaoshihao 2017-11-07
	function assist_apply_detail(){
		//详情
		$db_audit_main=M('db_audit_main');
		$where_find['db_audit_main.id']=$_REQUEST['id'];
		$result=$db_audit_main->where($where_find)->field('db_audit_main.*,work_nature,demand_depart,main_demand,confirm_message,confirm_evaluate,confirm_proposal,confirm_date,db_assist_apply.add_uid')->join('left join db_assist_apply on db_audit_main.id=db_assist_apply.mid')->find();
		//
		foreach(explode(",",$result['work_nature']) as $k1=>$v1){
			$work_nature[]=$this->get_db_universal_label(2,$v1);
		}
		$result['work_nature']=join(',',$work_nature);
		foreach(explode(",",$result['demand_depart']) as $k2=>$v2){
			$demand_depart[]=$this->get_db_universal_label(2,$v2);
		}
		$result['demand_depart']=join(',',$demand_depart);
		$result['dh_user']=$this->get_username($result['dh_uid']);
		$result['post_user']=$this->get_username($result['post_uid']);
		//人员
		$user=$this->get_user($result['add_uid']);
		$user['department_name']=$this->get_db_universal_label(2,$user['department_id']);
		$this->assign('user',$user);
		//项目
		$project=$this->get_project($result['pid']);
		$this->assign('project',$project);
		//文件
		$db_assist_apply=M('db_assist_apply');
		$where_de['mid']=$_REQUEST['id'];
		$detail=$db_assist_apply->where($where_de)->select();
		$this->assign('detail',$detail);
		$this->assign('ds',count($detail)-1);
		$this->assign('state',$_REQUEST['state']);
		//审核人员
		$audit_user=$this->audit_user(1,$result['audit_type']);
		foreach($audit_user as $kk=>$vv){
			if($result['status']>$vv['audit_sort']){
				switch($vv['audit_name']){
					case '营销部负责人':
						$audit_user[$kk]['audit_user']=$this->get_username($result['audit2_uid']);
						$audit_user[$kk]['audit_date']=$result['audit2_date'];
						$audit_user[$kk]['audit_comments']=$result['audit2_message'];
					break;
				}
			}
			if(empty($vv['audit_uid']) and empty($audit_user[$kk]['audit_user'])){unset($audit_user[$kk]);}
		}
		//判断项目负责人是否离职
		$judge_user1_user=$this->get_user($project['manager_uid']);
		if($judge_user1_user['status']!=1)
		{
			$project['manager_name']=$project['manager_name'].'(离职)';
		}
		$array1=array("audit_name"=>"项目负责人","audit_user"=>"".$project['manager_name']."","audit_comments"=>"".$result['audit1_message']."","audit_date"=>"".$result['audit1_date']."","audit_sort"=>"1");
		array_unshift($audit_user,$array1);
		$array2=array("audit_name"=>"申请人","audit_user"=>"".$result['post_user']."","audit_date"=>"".$result['post_date']."","audit_sort"=>"-1");
		array_unshift($audit_user,$array2);
		foreach($audit_user as $k1=>$v1){
			if($result['arrive_status']==$v1['audit_sort']){
				$arrive_name=$v1['audit_name'];
				if($result['arrive_status']=='-1'){$arrive_info=$result['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
				$arrive_date=$v1['audit_date'];
			}
			if($result['dh_status']==$v1['audit_sort']){
				$audit_user[$k1]['arrive_name']=$arrive_name;
				$audit_user[$k1]['dh_message']=$result['dh_message'];
				$audit_user[$k1]['dh_date']=$result['dh_date'];
				$audit_user[$k1]['arrive_info']=$arrive_info;
				$audit_user[$k1]['arrive_date']=$arrive_date;
			}
		}
		$this->assign('sum',count($audit_user));
		$this->assign('audit_user',$audit_user);
		foreach($audit_user as $ka=>$va){
			if($result['status']<=$va['audit_sort']){
				unset($audit_user[$ka]);
			}
		}
		$this->assign('audit_list',$audit_user);
		$audit_sh=$this->audit_type_next_person(1,$result['audit_type'],$result['status'],'egt');
		$audit_qs=$this->audit_type_next_person(1,$result['audit_type'],$result['status'],'lt');
		if($result['status']==1){
			if($project['manager_uid']==$this->login_id){
				$shenhe=1;
			}
		}else{
			if($result['status']!=-1){
				if(in_array($this->login_id,explode(',',$audit_sh['audit_uid']))){$shenhe=1;}
			}
		}
		if($result['status']==2){
			if($project['manager_uid']==$this->login_id){
				$qishen=1;
			}
		}else{
			if(in_array($this->login_id,explode(',',$audit_qs['audit_uid']))){$qishen=1;}
		}
		$this->assign('result',$result);
		$this->assign('shenhe',$shenhe);
		$this->assign('qishen',$qishen);
		$this->assign('no',$_REQUEST['no']);
		$this->display();
	}
	
	//协作申请表-->ajax designed by:zhaoshihao 2017-11-07
	function assist_apply_ajax(){
		if($_REQUEST['action']=='delete')
		{
			//删除审核表
			$db_audit_main=M('db_audit_main');
			$where_dl['id']=$_REQUEST['id'];
			$result_bool=$db_audit_main->where($where_dl)->delete();
			//删除主表
			$db_assist_apply=M('db_assist_apply');
			$where_del['mid']=$_REQUEST['id'];
			$file_list=$db_assist_apply->where($where_de)->select();
			foreach($file_list as $key=>$value)
			{
				$file1=str_replace("/dms_erp/uploads", "./uploads", $value['file_url']);
				if (file_exists($file1)) {
					@unlink($file1);
				}
			}
			$db_assist_apply->where($where_del)->delete();
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
	}
	
	//协作申请审核-->ajax designed by:zhaoshihao 2017-11-07
	function assist_apply_audit_ajax(){
		$db_audit_main=M('db_audit_main');
		$db_assist_apply=M('db_assist_apply');
		$status=$_REQUEST['status'];
		$up_where['id']=$_REQUEST['mid'];
		$find_result=$db_audit_main->where($up_where)->find();
		$project=$this->get_project($find_result['pid']);
		if($_REQUEST['state']==1){
			$sta=$this->audit_type_next_person(1,$find_result['audit_type'],$status,'egt');
			if($find_result['flow_status']==-1){
				if($find_result['status']==$find_result['arrive_status']){
					$status=$find_result['dh_status'];
				}
			}
		}elseif($_REQUEST['state']==2){
			if(($project['manager_uid']==$this->login_id) and ($find_result['status']==2)){
				$status=1;
				$sta['audit_sort']=1;
			}else{
				$sta=$this->audit_type_next_person(1,$find_result['audit_type'],$status,'lt');
				$status=$sta['audit_sort'];
			}
		}
		switch($status){
			case -1:
				if(!empty($_REQUEST['flow_status'])){
					if($_REQUEST['flow_status']==-1){
						$up_where=$this->audit_status_judge($_REQUEST['arrive_status']);
					}else{
						$up_where=$this->audit_status_judge_all($_REQUEST['arrive_status'],$_REQUEST['dh_status']);
					}
					$up_where['status']=$_REQUEST['arrive_status'];
					$up_where['id']=$_REQUEST['mid'];
				}else{
					$up_where['status']=-1;
					$up_where['post_uid']=NULL;$up_where['post_date']=NULL;
					$up_where['audit1_uid']=NULL;$up_where['audit1_date']=NULL;$up_where['audit1_message']=NULL;
					$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
				}
				if(!empty($_REQUEST['dh_message']))
				{
					$up_where['dh_uid']=$this->login_id;
					$up_where['dh_date']=date('Y-m-d H:i:s');
					$up_where['dh_message']=$_REQUEST['dh_message'];
					$up_where['dh_status']=$_REQUEST['dh_status'];
					$up_where['arrive_status']=$_REQUEST['arrive_status'];
					$up_where['flow_status']=$_REQUEST['flow_status'];
					$up_where['submit_info']=NULL;
				}else{
					if($find_result['status']!=1){
						unset($up_where);
					}
				}
				break;
			case 1:
				$up_where['audit1_uid']=NULL;$up_where['audit1_date']=NULL;$up_where['audit1_message']=NULL;
				$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
				if(!empty($_REQUEST['uuid'])){
					if($find_result['status']!=-1){
						unset($up_where);
					}else{
						$up_where['flow_status']=1;
						$up_where['status']=1;
						$up_where['post_uid']=$this->login_id;
						$up_where['post_date']=date('Y-m-d H:i:s');
					}
				}else{
					$up_where['status']=1;
					if($sta['audit_sort']!=$status){
						unset($up_where);
					}
				}
				break;
			case 2:
				$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
				if(!empty($_REQUEST['uuid'])){
					if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
						$up_where['status']=$status;
						$up_where['flow_status']=1;
						if($find_result['status']!=$find_result['arrive_status']){
							unset($up_where);
						}else{
							if($find_result['arrive_status']==-1){
								$up_where['post_uid']=$this->login_id;
								$up_where['post_date']=date('Y-m-d H:i:s');
							}else{
								$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
								$up_where['audit'.$find_result['arrive_status'].'_date']=date('Y-m-d H:i:s');
								$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit1_message'];
								$up_where['submit_info']=$_REQUEST['audit1_message'];
							}
						}
					}else{
						if($find_result['status']!=1){
							unset($up_where);
						}else{
							$up_where['status']=$sta['audit_sort'];
							$up_where['audit1_uid']=$this->login_id;
							$up_where['audit1_date']=date('Y-m-d H:i:s');
							$up_where['audit1_message']=$_REQUEST['audit1_message'];
						}
					}
				}else{
					$up_where['status']=$status;
					if($find_result['flow_status']==-1){
						if($find_result['dh_status']!=$status){
							unset($up_where);
						}
					}else{
						if($sta['audit_sort']!=$status){
							unset($up_where);
						}
					}
				}
				break;
			case 3:
				if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
					if($find_result['status']!=$find_result['arrive_status']){
						unset($up_where);
					}else{
						$up_where['flow_status']=1;
						$up_where['status']=$status;
						if($find_result['arrive_status']==-1){
							$up_where['post_uid']=$this->login_id;
							$up_where['post_date']=date('Y-m-d H:i:s');
						}else{
							$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
							$up_where['audit'.$find_result['arrive_status'].'_date']=date('Y-m-d H:i:s');
							$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit1_message'];
							$up_where['submit_info']=$_REQUEST['audit1_message'];
						}
					}
				}else{
					if($find_result['status']!=2){
						unset($up_where);
					}else{
						$up_where['status']=$status;
						$up_where['audit2_uid']=$this->login_id;
						$up_where['audit2_date']=date('Y-m-d H:i:s');
						$up_where['audit2_message']=$_REQUEST['audit1_message'];
					}
				}
				break;
			case 4:
				if($find_result['status']!=3){
					unset($up_where);
				}else{
					$up_where['status']=$status;
					$wass['mid']=$_REQUEST['mid'];
					$ass['confirm_date']=date('Y-m-d H:i:s');
					$ass['confirm_proposal']=$_REQUEST['confirm_proposal'];
					$ass['confirm_evaluate']=$_REQUEST['confirm_evaluate'];
					$ass['confirm_message']=$_REQUEST['confirm_message'];
					$db_assist_apply->where($wass)->save($ass);
				}
				break;
		}
		if($_REQUEST['submit_info']){$up_where['submit_info']=$_REQUEST['submit_info'];}
		$data['status']=$db_audit_main->save($up_where);
		$data['state']=$_REQUEST['state'];
		echo json_encode($data);die;
	}
	
	//日程管理列表 designed by:zhaoshihao 2017-12-05
	function schedule_list(){
		//赋值
		/*
		$kc_user=M('kc_user');
		if(preg_match("/F01/",$this->login_permissions_rule))
		{
			$where_user['_string']="status=1 or disable_date>='".date("Y-m-25",strtotime('-1 month'))."'";
			$user_list=$kc_user->where($where_user)->order('spell')->select();
			$this->assign('user_list',$user_list);
		}
		elseif($this->get_kc_universal_user(29,2)==1)
		{
			$where_user['_string']="(status=1 and person_coefficient!=0) or disable_date>='".date("Y-m-25",strtotime('-1 month'))."'";
			$user_list=$kc_user->where($where_user)->order('spell')->select();
			$this->assign('user_list',$user_list);
		}
		else
		{
			if($uid!=$this->login_id){$this->error('您没有对应权限!');}
		}
		*/
		$this->display();
	}
	
	//日程管理列表 designed by:zhaoshihao 2017-12-05
	function schedule_other(){
		//赋值
		if(!empty($_REQUEST['type'])){$type=$_REQUEST['type'];}else{$type=-10;}
		$this->assign('type',$type);
		$db_schedule=M('db_schedule');
		$db_schedule_detail=M('db_schedule_detail');
		$where['add_uid']=$this->login_id;
		if($type!=-10){$where['type']=$type;}
		$count=$db_schedule->field('db_schedule.id')->where($where)->join('left join db_schedule_detail on db_schedule.id=db_schedule_detail.mid')->group('db_schedule.id')->select();
		$Page = new \Think\Page(count($count),15);
		$show=$Page->show();
		$result=$db_schedule->field('db_schedule.*')->where($where)->join('left join db_schedule_detail on db_schedule.id=db_schedule_detail.mid')->order('date desc')->group('db_schedule.id')->limit($Page->firstRow.','.$Page->listRows)->select();
		$db_audit_main=M('db_audit_main');
		foreach($result as $key=>$value){
			//项目
			$pd=$this->get_project($value['pid']);
			$result[$key]['project_num']=$pd['project_num'];
			$result[$key]['project_name']=$pd['project_name'];
			$result[$key]['manager_user']=$this->get_username($pd['manager_uid']);
			//详情
			$where_d['mid']=$value['id'];
			$result[$key]['detail']=$db_schedule_detail->where($where_d)->select();
			//类型
			$type_name=$this->get_db_universal_type(11,1,NULL,NULL,$value['type']);
			$result[$key]['type_name']=$type_name['name2'];
			$fill_post_name=$this->get_db_universal_type(12,1,NULL,NULL,$value['fill_post']);
			$result[$key]['fill_post_name']=$fill_post_name['name2'];
			$work_type_name=$this->get_db_universal_type(13,1,NULL,NULL,$value['work_type']);
			$result[$key]['work_type_name']=$work_type_name['name2'];
			if(empty($value['agent_post']) and !empty($value['agent'])){
				$user=$this->get_user($value['agent']);
				$result[$key]['agent']=$user['username'];
				$result[$key]['agent_post']=$this->get_db_universal_label(2,$user['position_id']);
				$result[$key]['agent_tel']=$user['mobilephone'];
			}
			//能否编辑
			foreach($result[$key]['detail'] as $kk=>$vv){
				$second1=strtotime($vv['date']);
				$second2=strtotime(date('Y-m-d'));
				if(($second1-$second2)/86400>7){
					$result[$key]['noedit']=1;
				}
				if(($second2-$second1)/86400>7){
					$result[$key]['noedit']=1;
				}
			}
			//休息审核详情
			$where_m['audit_id']=$value['id'];
			$where_m['type']=4;
			$audit=$db_audit_main->where($where_m)->find();
			$result[$key]['order_number']=$audit['order_number'];
			$result[$key]['audit_type']=$audit['audit_type'];
			$result[$key]['status']=$audit['status'];
			$result[$key]['audit_id']=$audit['id'];
			$result[$key]['dh_message']=$audit['dh_message'];
			$result[$key]['arrive_status']=$audit['arrive_status'];
			$result[$key]['submit_info']=$audit['submit_info'];
			$result[$key]['dh_date']=$audit['dh_date'];
			$result[$key]['dh_user']=$this->get_username($audit['dh_uid']);
			//
			if($value['type']==1){
				$result[$key]['color']='#a9d26a';
			}elseif($value['type']==2){
				$result[$key]['color']='#4680fe';
			}elseif($value['type']==3){
				$result[$key]['color']='#fb607f';
				if($audit['status']==1 || $audit['status']==2){
					$audit_useraa=$this->audit_type_next(4,$audit['audit_type'],$audit['status']);
				}
				$result[$key]['audit_useraa']=$audit_useraa['audit_user'];
				//审核流程
				$project=$this->get_project($value['pid']);
				$audit_user=$this->audit_type_next(4,$audit['audit_type'],$audit['status']);
				$result[$key]['audit_user']=$audit_user['audit_user'];
				//审核人员
				$audit_arr=$this->audit_user(4,$audit['audit_type']);
				foreach($audit_arr as $kk=>$vv){
					if($audit['status']>$vv['audit_sort']){
						switch($vv['audit_name']){
							case '日程管理负责人':
								$audit_arr[$kk]['audit_user']=$this->get_username($audit['audit2_uid']);
								$audit_arr[$kk]['audit_date']=$audit['audit2_date'];
								$audit_arr[$kk]['audit_comments']=$audit['audit2_message'];
							break;
						}
					}
					if(((empty($vv['audit_uid'])) and (empty($audit_arr[$kk]['audit_date']))) or ((empty($audit_arr[$kk]['audit_user'])) and (empty($audit_arr[$kk]['audit_date'])))){unset($audit_arr[$kk]);}
				}
				$array1=array("audit_name"=>"项目负责人","audit_user"=>"".$project['manager_name']."","audit_comments"=>"".$audit['audit1_message']."","audit_date"=>"".$audit['audit1_date']."","audit_sort"=>"1");
				array_unshift($audit_arr,$array1);
				$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($audit['post_uid'])."","audit_date"=>"".$audit['post_date']."","audit_sort"=>"-1");
				array_unshift($audit_arr,$array2);
				foreach($audit_arr as $k1=>$v1){
					if($audit['arrive_status']==$v1['audit_sort']){
						$arrive_name=$v1['audit_name'];
						if($audit['arrive_status']=='-1'){$arrive_info=$audit['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
						$arrive_date=$v1['audit_date'];
					}
					if($audit['dh_status']==$v1['audit_sort']){
						$audit_arr[$k1]['arrive_name']=$arrive_name;
						$audit_arr[$k1]['dh_message']=$audit['dh_message'];
						$audit_arr[$k1]['dh_date']=$audit['dh_date'];
						$audit_arr[$k1]['arrive_info']=$arrive_info;
						$audit_arr[$k1]['arrive_date']=$arrive_date;
					}
				}
				$result[$key]['audit_arr']=$audit_arr;
				foreach($audit_arr as $ka=>$va){
				if($audit['arrive_status']==$va['audit_sort'] and !empty($audit['submit_info'])){
					$result[$key]['submit_user']=$va['audit_user'];
				}
			}
			}elseif($value['type']==4){
				$result[$key]['color']='#8d81c9';
			}
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		$this->display();
	}
	
	//日程管理列表-->添加弹框 designed by:zhaoshihao 2017-12-05
	function schedule_list_add(){
		//如果有id查询详情
		$db_schedule=M('db_schedule');
		$where['id']=$_REQUEST['id'];
		$data=$db_schedule->where($where)->find();
		if(!empty($data)){
			$db_schedule_detail=M('db_schedule_detail');
			$where_d['mid']=$_REQUEST['id'];
			$detail=$db_schedule_detail->where($where_d)->order('date')->select();
			foreach($detail as $key=>$val){
				$second1=strtotime($val['date']);
				$second2=strtotime(date('Y-m-d'));
				if(($second1-$second2)/86400>7){
					$data['noedit']=1;
				}
				if(($second2-$second1)/86400>7){
					$data['noedit']=1;
				}
				if($key==0){
					$show_date=$val['date'];
				}
				if(count($detail)!=1){
					if($key+1==count($detail)){
						$show_date2=$val['date'];
					}
				}
			}
			//项目
			$pd=$this->get_project($data['pid']);
			$data['project_num']=$pd['project_num'];
			$data['project_name']=$pd['project_name'];
			//休息选择项目人员
			$pj=$this->get_project($data['pid']);
			$project_bg=$this->get_project_bg($data['pid']);
			//姓名下拉菜单
			if($project_bg['status']==1){
				$use=array();
				$use[]=$pj['manager_uid'];
				$use[]=$pj['director_uid'];
				$db_project_user=M('db_project_user');
				$where_u['pid']=$data['pid'];
				if(!empty($show_date2)){
					$where_u['_string']="(('".$show_date."'<=come_date and '".$show_date2."'>`out_date`) or ('".$show_date."'<=come_date and out_date is NULL))";
				}else{
					$where_u['_string']="(('".$show_date."'>=come_date and '".$show_date."'<`out_date`) or ('".$show_date."'>=come_date and out_date is NULL))";
				}
				$result=$db_project_user->where($where_u)->order('come_date desc')->group('uid')->select();
				foreach($result as $key=>$value){
					if($value['uid']!=$this->login_id){
						$use[]=$value['uid'];
					}
				}
				$use=array_flip(array_flip($use));
				$uses=join(',',$use);
				$users=$this->get_all_username(1,NULL,NULL,NULL,$uses);
				foreach($users as $key=>$value){
					$user=$this->get_user($value['id']);
					$users[$key]['position']=$user['position_descr'];
					$users[$key]['mobilephone']=$user['mobilephone'];
				}
			}
			$this->assign('users',$users);
			//工作类型
			$work_type_name=$this->get_db_universal_type(13,1,NULL,NULL,$data['work_type']);
			if(!empty($data)){
				$data['work_type_name']=$work_type_name['name3'];
				$data['work_name']=$work_type_name['name2'];
				$userd=$this->get_user($data['agent']);
				$data['agent_name']=$userd['username'];
				$data['position']=$userd['position_descr'];
				$data['mobilephone']=$userd['mobilephone'];
			}
			//休息审核
			$db_audit_main=M('db_audit_main');
			$where_m['audit_id']=$_REQUEST['id'];
			$where_m['type']=4;
			$audit=$db_audit_main->where($where_m)->find();
			$data['order_number']=$audit['order_number'];
			$data['audit_type']=$audit['audit_type'];
			$data['status']=$audit['status'];
			$data['audit_id']=$audit['id'];
			$data['dh_message']=$audit['dh_message'];
			$data['arrive_status']=$audit['arrive_status'];
			$data['dh_date']=$audit['dh_date'];
			$data['submit_info']=$audit['submit_info'];
			$data['dh_user']=$this->get_username($audit['dh_uid']);
		}
		if($_REQUEST['way']=='1'){
			//工作类型
			$work_type=$this->get_db_universal_type(13);
			$this->assign('work_type',$work_type);
			$this->assign('data',$data);
			$this->display('schedule_list_zg');
		}elseif($_REQUEST['way']=='3'){
			//审核人员
			$audit_user=$this->audit_user(4,$audit['audit_type']);
			foreach($audit_user as $kk=>$vv){
				if($audit['status']>$vv['audit_sort']){
					switch($vv['audit_name']){
						case '日程管理负责人':
							$audit_user[$kk]['audit_user']=$this->get_username($audit['audit2_uid']);
							$audit_user[$kk]['audit_date']=$audit['audit2_date'];
							$audit_user[$kk]['audit_comments']=$audit['audit2_message'];
						break;
					}
				}
				if(empty($vv['audit_uid']) and empty($audit_user[$kk]['audit_user'])){unset($audit_user[$kk]);}
			}
			//判断项目负责人是否离职
			$judge_user1_user=$this->get_user($pj['manager_uid']);
			if($judge_user1_user['status']!=1)
			{
				$pj['manager_name']=$pj['manager_name'].'(离职)';
			}
			$array1=array("audit_name"=>"项目负责人","audit_user"=>"".$pj['manager_name']."","audit_date"=>"".$audit['audit1_date']."","audit_comments"=>"".$audit['audit1_message']."","audit_sort"=>"1");
			array_unshift($audit_user,$array1);
			$array2=array("audit_name"=>"添加人","audit_user"=>"".$this->get_username($audit['add_uid'])."","audit_date"=>"".$audit['add_date']."","audit_sort"=>"-1");
			array_unshift($audit_user,$array2);
			foreach($audit_user as $k1=>$v1){
				if($audit['arrive_status']==$v1['audit_sort']){
					$arrive_name=$v1['audit_name'];
					if($audit['arrive_status']=='-1'){$arrive_info=$audit['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
					$arrive_date=$v1['audit_date'];
				}
				if($audit['dh_status']==$v1['audit_sort']){
					$audit_user[$k1]['arrive_name']=$arrive_name;
					$audit_user[$k1]['dh_message']=$audit['dh_message'];
					$audit_user[$k1]['dh_date']=$audit['dh_date'];
					$audit_user[$k1]['arrive_info']=$arrive_info;
					$audit_user[$k1]['arrive_date']=$arrive_date;
				}
			}
			$this->assign('sum',count($audit_user));
			$this->assign('audit_user',$audit_user);
			foreach($audit_user as $ka=>$va){
				if($data['arrive_status']==$va['audit_sort'] and !empty($data['submit_info'])){
					$data['submit_user']=$va['audit_user'];
				}
			}
			$this->assign('data',$data);
			$this->display('schedule_list_xx');
		}elseif($_REQUEST['way']=='4'){
			$this->assign('data',$data);
			$this->display('schedule_list_qj');
		}
	}
	
	//日程管理列表-->添加提交 designed by:zhaoshihao 2017-12-05
	function schedule_list_doadd(){
		$db_schedule=M('db_schedule');
		$db_schedule_detail=M('db_schedule_detail');
		//判断日期内填报类型是否有重复
		if(!empty($_REQUEST['tdate'])){
			$where['date']=$_REQUEST['tdate'];
			$where['add_uid']=$this->login_id;
			$have=$db_schedule->field('db_schedule.type')->where($where)->join('left join db_schedule_detail on db_schedule.id=db_schedule_detail.mid')->group('db_schedule.id')->select();
			foreach($have as $key=>$val){
				if($val['type']==$_REQUEST['ttype']){
					$data['status']=self::NO;
					echo json_encode($data);die;
				}
			}
		}else{
			$where_a['date']=array('between',array($_REQUEST['tdate2'],$_REQUEST['tdate3']));
			$where_a['add_uid']=$this->login_id;
			$datas=$db_schedule->field('db_schedule.type')->where($where_a)->join('left join db_schedule_detail on db_schedule.id=db_schedule_detail.mid')->group('db_schedule.id')->select();
			foreach($datas as $key=>$val){
				if($val['type']==$_REQUEST['ttype']){
					$data['status']=self::NO;
					echo json_encode($data);die;
				}
			}
		}
		$db_schedule=M('db_schedule');
		$where['pid']=$_REQUEST['pid'];
		$where['fill_post']=$_REQUEST['fill'];
		$where['type']=$_REQUEST['ttype'];
		if(!empty($_REQUEST['matter_id'])){$where['matter_id']=$_REQUEST['matter_id'];}
		if(!empty($_REQUEST['work_type'])){$where['work_type']=$_REQUEST['work_type'];}
		if(!empty($_REQUEST['work_content'])){$where['work_content']=$_REQUEST['work_content'];}
		if(!empty($_REQUEST['agent_post'])){
			$where['agent']=$_REQUEST['agent_name'];
			$where['agent_post']=$_REQUEST['agent_post'];
			$where['agent_tel']=$_REQUEST['agent_tel'];
		}else{
			if(!empty($_REQUEST['agent'])){$where['agent']=$_REQUEST['agent'];}
		}
		if(!empty($_REQUEST['ekp'])){$where['ekp']=$_REQUEST['ekp'];}
		$where['add_uid']=$this->login_id;
		$where['add_date']=date('Y-m-d H:i:s');
		$result_bool=$db_schedule->add($where);
		//是休息插入审核表
		if($_REQUEST['ttype']==3){
			$db_audit_main=M('db_audit_main');
			$field='XX';
			$where_s['type']=3;
			$where_s['order_number']=array('like',$field.date('Ymd').'%');
			$result=$db_audit_main->field('order_number')->where($where_s)->order('order_number desc')->find();
			if(empty($result))
			{
				$item=$field.date('Ymd').'001';
			}
			else
			{
				$item=$field.(substr($result['order_number'],2)+1);
			}
			$where_au['pid']=$_REQUEST['pid'];
			$where_au['audit_id']=$result_bool;
			$where_au['order_number']=$item;
			$pd=$this->get_project($_REQUEST['pid']);
			$where_au['audit_type']=$pd['center_id'];
			$where_au['status']=1;
			$where_au['type']=4;
			$where_au['add_uid']=$this->login_id;
			$where_au['add_date']=date('Y-m-d H:i:s');
			$where_au['post_uid']=$this->login_id;
			$where_au['post_date']=date('Y-m-d H:i:s');
			$db_audit_main->add($where_au);
		}
		//副表
		if(!empty($_REQUEST['tdate'])){
			$where_d['mid']=$result_bool;
			$where_d['date']=$_REQUEST['tdate'];
			$timearray=explode("-",$_REQUEST['tdate']);
			$where_d['year']=$timearray[0];
			$where_d['month']=$timearray[1];
			$where_d['day']=$timearray[2];
			$where_d['week']=date('W',strtotime($_REQUEST['tdate']));
			$db_schedule_detail->add($where_d);
		}else{
			$start_date = strtotime($_REQUEST['tdate2']);
			$end_date = strtotime($_REQUEST['tdate3']);
			// 计算日期段内有多少天
			$days = ($end_date-$start_date)/86400+1;
			// 保存每天日期
			$date = array();
			for($i=0; $i<$days; $i++){
				$date[] = date('Y-m-d', $start_date+(86400*$i));
			}
			foreach($date as $key=>$val){
				$where_d['mid']=$result_bool;
				$where_d['date']=$val;
				$timearray=explode("-",$val);
				$where_d['year']=$timearray[0];
				$where_d['month']=$timearray[1];
				$where_d['day']=$timearray[2];
				$where_d['week']=date('W',strtotime($val));
				$db_schedule_detail->add($where_d);
			}
		}
		if($result_bool)
		{
			$data['status']=self::YES;
		}
		else
		{
			$data['status']=self::NO;
		}
		echo json_encode($data);die;
	}
	
	//日程管理列表-->编辑/详情 designed by:zhaoshihao 2017-12-05
	function schedule_list_edit(){
		$db_schedule=M('db_schedule');
		$where['id']=$_REQUEST['id'];
		$data['detail']=$db_schedule->where($where)->find();
		$db_schedule_detail=M('db_schedule_detail');
		$where_d['mid']=$_REQUEST['id'];
		$detail=$db_schedule_detail->where($where_d)->order('date')->select();
		foreach($detail as $key=>$val){
			$second1=strtotime($val['date']);
			$second2=strtotime(date('Y-m-d'));
			if(($second1-$second2)/86400>7){
				$data['detail']['noedit']=1;
			}
			if(($second2-$second1)/86400>7){
				$data['detail']['noedit']=1;
			}
			$date[]=$val['date'];
			if($key==0){
				$data['detail']['show_date']=$val['date'];
			}
			if(count($detail)!=1){
				if($key+1==count($detail)){
				$data['detail']['show_date'].='~'.$val['date'];
				}
			}
			if(count($detail)==1){
				$data['detail']['date']=$val['date'];
			}
		}
		$pd=$this->get_project($data['detail']['pid']);
		$data['detail']['project']='['.$pd['project_num'].']'.$pd['project_name'];
		$fill_post_name=$this->get_db_universal_type(12,1,NULL,NULL,$data['fill_post']);
		$data['detail']['fill_post_name']=$fill_post_name['name2'];
		sort($date);
		$start=reset($date);
		$end=end($date);
		if(count($detail)>1){
			$data['detail']['start_date']=$start;
			$data['detail']['end_date']=$end;
		}
		$type_name=$this->get_db_universal_type(11,1,NULL,NULL,$data['detail']['type']);
		$data['detail']['type_name']=$type_name['name2'];
		//休息审核
		$db_audit_main=M('db_audit_main');
		$where_m['audit_id']=$_REQUEST['id'];
		$where_m['type']=4;
		$audit=$db_audit_main->where($where_m)->find();
		$data['detail']['order_number']=$audit['order_number'];
		$data['detail']['audit_type']=$audit['audit_type'];
		$data['detail']['status']=$audit['status'];
		$data['detail']['audit_id']=$audit['id'];
		//所有项目
		$project=array();
		$db_project_user=M('db_project_user');
		$db_project=M('db_project');
		
		$where_p['_string']="(manager_uid=".$this->login_id.") or (director_uid=".$this->login_id.")";
		$where_p['status']=1;
		$where_p['center_id']=130005;
		$where_p['info_id']=array('exp','IS NULL');
		$pro=$db_project->where($where_p)->group('id')->select();
		foreach($pro as $ka=>$va){
			$project[]=$va['id'];
		}
			
		$where_u['uid']=$this->login_id;
		$where_u['pid']=array('exp','is not NULL');
		if(count($detail)==1){
			$where_u['_string']="(('".$start."'>=come_date and '".$start."'<`out_date`) or ('".$start."'>=come_date and out_date is NULL))";
		}else{
			$where_u['_string']="(('".$start."'<=come_date and '".$end."'>`out_date`) or ('".$start."'<=come_date and out_date is NULL))";
		}
		$puser=$db_project_user->where($where_u)->group('pid')->select();
		foreach($puser as $ka=>$va){
			$project[]=$va['pid'];
		}
		$project=array_unique($project);
		rsort($project);
		$where_ps['id']=array('in',join(',',$project));
		$where_ps['status']=1;
		if($this->login_id==1){unset($where_ps);$where_ps['status']=1;$where_ps['center_id']=130005;$where_ps['info_id']=array('exp','IS NULL');}
		$project_list=$db_project->where($where_ps)->order('id desc')->select();
		$data['plist']=$project_list;
		//填报岗位
		$data['fill_post']=$this->get_db_universal_type(12);
		//工作类型
		$data['work_type']=$this->get_db_universal_type(13);
		echo json_encode($data);die;
	}
	
	//日程管理列表-->编辑提交 designed by:zhaoshihao 2017-12-05
	function schedule_list_doedit(){
		$db_schedule=M('db_schedule');
		$where['id']=$_REQUEST['id'];
		$asd=$db_schedule->where($where)->find();
		$where['pid']=$_REQUEST['pid'];
		$where['fill_post']=$_REQUEST['fill'];
		if(!empty($_REQUEST['matter_id'])){$where['matter_id']=$_REQUEST['matter_id'];}
		if(!empty($_REQUEST['work_type'])){$where['work_type']=$_REQUEST['work_type'];}
		if(!empty($_REQUEST['work_content'])){$where['work_content']=$_REQUEST['work_content'];}
		if(!empty($_REQUEST['agent_name'])){
			$where['agent']=$_REQUEST['agent_name'];
			$where['agent_post']=$_REQUEST['agent_post'];
			$where['agent_tel']=$_REQUEST['agent_tel'];
		}else{
			$where['agent']=$_REQUEST['agent'];
			$where['agent_post']=NULL;
			$where['agent_tel']=NULL;
		}
		if(!empty($_REQUEST['ekp'])){$where['ekp']=$_REQUEST['ekp'];}
		$result_bool=$db_schedule->save($where);
		/*
		if($asd['type']==3){
			$db_audit_main=M('db_audit_main');
			$where_sa['audit_id']=$_REQUEST['id'];
			$where_sa['type']=4;
			$where_au['pid']=$_REQUEST['pid'];
			$pd=$this->get_project($_REQUEST['pid']);
			$where_au['audit_type']=$pd['center_id'];
			$where_au['status']=1;
			$where_au['post_uid']=$this->login_id;
			$where_au['post_date']=date('Y-m-d H:i:s');
			$db_audit_main->where($where_sa)->save($where_au);
		}
		*/
		if($result_bool)
		{
			$data['status']=self::YES;
		}
		else
		{
			$data['status']=self::NO;
		}
		echo json_encode($data);die;
	}
	
	//日程管理列表-->ajax designed by:zhaoshihao 2017-12-05
	function schedule_list_ajax(){
		if($_REQUEST['action']=='type'){
			//填报类型
			$type=$this->get_db_universal_type(11);
			$db_schedule=M('db_schedule');
			$db_schedule_detail=M('db_schedule_detail');
			if(empty($_REQUEST['date'])){
				$start=$_REQUEST['start'];
				$end=$_REQUEST['end'];
				$where_a['date']=array('between',array($start,$end));
			}else{
				$where_a['date']=$_REQUEST['date'];
			}
			$where_a['add_uid']=$this->login_id;
			$datas=$db_schedule->field('db_schedule.*')->where($where_a)->join('left join db_schedule_detail on db_schedule.id=db_schedule_detail.mid')->group('db_schedule.id')->select();
			foreach($datas as $key=>$val){
				foreach($type as $kk=>$vv){
					if($val['type']==$vv['name1']){
						unset($type[$kk]);
					}
				}
			}
			if(!empty($type)){
				$data['has_type']=1;
				foreach($type as $kk=>$vv){
					$data['way']=$vv['name1'];
					break;
				}
			}
			$type=array_values($type);
			$data['type']=$type;
			$data['fill_post']=$this->get_db_universal_type(12);
			$data['work_type']=$this->get_db_universal_type(13);
			//填报项目筛选
			//所有项目
			$project=array();
			$db_project_user=M('db_project_user');
			$db_project=M('db_project');
			
			$where_p['_string']="(manager_uid=".$this->login_id.") or (director_uid=".$this->login_id.")";
			$where_p['status']=1;
			$where_p['center_id']=130005;
			$where_p['info_id']=array('exp','IS NULL');
			$pro=$db_project->where($where_p)->group('id')->select();
			foreach($pro as $ka=>$va){
				$project[]=$va['id'];
			}
			
			$where_u['uid']=$this->login_id;
			$where_u['pid']=array('exp','is not NULL');
			if(!empty($_REQUEST['date'])){
				$where_u['_string']="(('".$_REQUEST['date']."'>=come_date and '".$_REQUEST['date']."'<`out_date`) or ('".$_REQUEST['date']."'>=come_date and out_date is NULL))";
			}else{
				$where_u['_string']="(('".$_REQUEST['start']."'<=come_date and '".$_REQUEST['end']."'>`out_date`) or ('".$_REQUEST['start']."'<=come_date and out_date is NULL))";
			}
			$puser=$db_project_user->where($where_u)->group('pid')->select();
			foreach($puser as $ka=>$va){
				$project[]=$va['pid'];
			}
			$project=array_unique($project);
			rsort($project);
			$where_ps['id']=array('in',join(',',$project));
			$where_ps['status']=1;
			if($this->login_id==1){unset($where_ps);$where_ps['status']=1;$where_ps['center_id']=130005;$where_ps['info_id']=array('exp','IS NULL');}
			$data['plist']=$db_project->where($where_ps)->group('id')->order('id desc')->select();
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='user'){
			$db_schedule_detail=M('db_schedule_detail');
			if(!empty($_REQUEST['mid'])){
				$where_d['mid']=$_REQUEST['mid'];
				$detail=$db_schedule_detail->where($where_d)->order('date')->select();
				foreach($detail as $key=>$val){
					if($key==0){
						$show_date=$val['date'];
					}
					if(count($detail)!=1){
						if($key+1==count($detail)){
							$show_date2=$val['date'];
						}
					}
				}
				if(!empty($show_date2)){
					$where['_string']="(('".$show_date."'<=come_date and '".$show_date2."'>`out_date`) or ('".$show_date."'<=come_date and out_date is NULL))";
				}else{
					$where['_string']="(('".$show_date."'>=come_date and '".$show_date."'<`out_date`) or ('".$show_date."'>=come_date and out_date is NULL))";
				}
			}else{
				if(!empty($_REQUEST['date'])){
					$where['_string']="(('".$_REQUEST['date']."'>=come_date and '".$_REQUEST['date']."'<`out_date`) or ('".$_REQUEST['date']."'>=come_date and out_date is NULL))";
				}else{
					$where['_string']="(('".$_REQUEST['start']."'<=come_date and '".$_REQUEST['end']."'>`out_date`) or ('".$_REQUEST['start']."'<=come_date and out_date is NULL))";
				}
			}
			//休息选择项目人员
			//姓名下拉菜单
			$pj=$this->get_project($_REQUEST['id']);
			$use=array();
			$use[]=$pj['manager_uid'];
			$use[]=$pj['director_uid'];
			$db_project_user=M('db_project_user');
			$where['pid']=$_REQUEST['id'];
			$result=$db_project_user->where($where)->order('come_date desc')->group('uid')->select();
			foreach($result as $key=>$value){
				if($value['uid']!=$this->login_id){
					$use[]=$value['uid'];
				}
			}
			$use=array_flip(array_flip($use));
			$uses=join(',',$use);
			$data=$this->get_all_username(1,NULL,NULL,NULL,$uses);
			foreach($data as $key=>$value){
				$user=$this->get_user($value['id']);
				$data[$key]['position']=$user['position_descr'];
				$data[$key]['mobilephone']=$user['mobilephone'];
			}
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='detail'){
			$timearray=explode("-",$_REQUEST['date']);
			$year=$timearray[0];
			$month=$timearray[1];
			//当前月数据
			$db_schedule=M('db_schedule');
			$db_schedule_detail=M('db_schedule_detail');
			$firstday=$this->get_date(NULL,"-1 month",$year.'-'.$month);
			$lastday=$this->get_date(NULL,"+1 month",$year.'-'.$month);
			$lastday=date('Y-m-d', strtotime("$lastday +1 month -1 day"));
			$where_a['date']=array('between',array($firstday,$lastday));
			$where_a['add_uid']=$this->login_id;
			$data=$db_schedule->field('db_schedule.*')->where($where_a)->join('left join db_schedule_detail on db_schedule.id=db_schedule_detail.mid')->group('db_schedule.id')->order('date')->select();
			foreach($data as $kk=>$vv){
				$project=$this->get_project($vv['pid']);
				$data[$kk]['project_name']=$project['project_name'];
				$where_de['mid']=$vv['id'];
				$where_de['date']=array('between',array($firstday,$lastday));
				$detail=$db_schedule_detail->where($where_de)->order('date')->select();
				$data[$kk]['start_date']=$detail[0]['date'];
				$end_date=$detail[count($detail)-1]['date'];
				$data[$kk]['end_date']=$this->get_date(NULL,"+1 day",$end_date);
				if($vv['type']==1){
					$data[$kk]['color']='#a9d26a';
				}elseif($vv['type']==2){
					$data[$kk]['color']='#4680fe';
				}elseif($vv['type']==3){
					$data[$kk]['color']='#fb607f';
				}elseif($vv['type']==4){
					$data[$kk]['color']='#8d81c9';
				}
			}
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='dates'){
			//判断点击日期是否在14天内
			$second1=strtotime($_REQUEST['date']);
			$second2=strtotime(date('Y-m-d'));
			if(($second1-$second2)/86400>7){
				$data['nodate']=1;
			}
			if(($second2-$second1)/86400>7){
				$data['nodate']=1;
			}
			$data['date']=$_REQUEST['date'];
			echo json_encode($data);die;
		}
	}
	
	//日程管理列表-->删除 designed by:zhaoshihao 2017-12-05
	function schedule_list_action(){
		$db_schedule=M('db_schedule');
		$where['id']=$_REQUEST['id'];
		$db_schedule->where($where)->delete();
		$db_schedule_detail=M('db_schedule_detail');
		$where_s['mid']=$_REQUEST['id'];
		$db_schedule_detail->where($where_s)->delete();
		$db_audit_main=M('db_audit_main');
		$where_m['audit_id']=$_REQUEST['id'];
		$where_m['type']=4;
		$db_audit_main->where($where_m)->delete();
		$data['status']=self::YES;
		echo json_encode($data);die;
	}
	
	//日程管理列表审核ajax designed by:zhaoshihao 2017-12-05
	function schedule_list_audit_ajax(){
		$db_audit_main=M('db_audit_main');
		$status=$_REQUEST['status'];
		$up_where['id']=$_REQUEST['mid'];
		$up_where['type']=4;
		$find_result=$db_audit_main->where($up_where)->find();
		$project=$this->get_project($find_result['pid']);
		if($_REQUEST['state']==1){
			$sta=$this->audit_type_next_person(4,$find_result['audit_type'],$status,'egt');
			if($find_result['flow_status']==-1){
				if($find_result['status']==$find_result['arrive_status']){
					$status=$find_result['dh_status'];
				}
			}
		}elseif($_REQUEST['state']==2){
			if(($project['manager_uid']==$this->login_id) and ($find_result['status']==2)){
				$status=1;
				$sta['audit_sort']=1;
			}else{
				$sta=$this->audit_type_next_person(4,$find_result['audit_type'],$status,'lt');
				$status=$sta['audit_sort'];
			}
		}
		switch($status){
			case -1:
				if(!empty($_REQUEST['flow_status'])){
					if($_REQUEST['flow_status']==-1){
						$up_where=$this->audit_status_judge($_REQUEST['arrive_status']);
					}else{
						$up_where=$this->audit_status_judge_all($_REQUEST['arrive_status'],$_REQUEST['dh_status']);
					}
					$up_where['status']=$_REQUEST['arrive_status'];
					$up_where['id']=$_REQUEST['mid'];
				}else{
					$up_where['status']=-1;
					$up_where['audit1_uid']=NULL;$up_where['audit1_date']=NULL;$up_where['audit1_message']=NULL;
					$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
				}
				if(!empty($_REQUEST['dh_message']))
				{
					$up_where['dh_uid']=$this->login_id;
					$up_where['dh_date']=date('Y-m-d H:i:s');
					$up_where['dh_message']=$_REQUEST['dh_message'];
					$up_where['dh_status']=$_REQUEST['dh_status'];
					$up_where['arrive_status']=$_REQUEST['arrive_status'];
					$up_where['flow_status']=$_REQUEST['flow_status'];
					$up_where['submit_info']=NULL;
				}else{
					if($find_result['status']!=1){
						unset($up_where);
					}
				}
				break;
			case 1:
				$up_where['status']=$sta['audit_sort'];
				$up_where['audit1_uid']=NULL;$up_where['audit1_date']=NULL;$up_where['audit1_message']=NULL;
				$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
				if(!empty($_REQUEST['uuid'])){
					if($find_result['status']!=-1){
						unset($up_where);
					}else{
						$up_where['flow_status']=1;
						$up_where['status']=1;
						$up_where['post_uid']=$this->login_id;
						$up_where['post_date']=date('Y-m-d H:i:s');
					}
				}else{
					$up_where['status']=1;
					if($sta['audit_sort']!=$status){
						unset($up_where);
					}
				}
				break;
			case 2:
				$up_where['audit2_uid']=NULL;$up_where['audit2_date']=NULL;$up_where['audit2_message']=NULL;
				if(!empty($_REQUEST['uuid'])){
					if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
						$up_where['status']=$status;
						$up_where['flow_status']=1;
						if($find_result['status']!=$find_result['arrive_status']){
							unset($up_where);
						}else{
							if($find_result['arrive_status']==-1){
								$up_where['post_uid']=$this->login_id;
								$up_where['post_date']=date('Y-m-d H:i:s');
							}else{
								$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
								$up_where['audit'.$find_result['arrive_status'].'_date']=date('Y-m-d H:i:s');
								$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit1_message'];
								$up_where['submit_info']=$_REQUEST['audit1_message'];
							}
						}
					}else{
						$up_where['status']=$sta['audit_sort'];
						if($find_result['status']!=1){
							unset($up_where);
						}else{
							$up_where['audit1_uid']=$this->login_id;
							$up_where['audit1_date']=date('Y-m-d H:i:s');
							$up_where['audit1_message']=$_REQUEST['audit1_message'];
						}
					}
				}else{
					$up_where['status']=$status;
					if($find_result['flow_status']==-1){
						if($find_result['dh_status']!=$status){
							unset($up_where);
						}
					}else{
						if($sta['audit_sort']!=$status){
							unset($up_where);
						}
					}
				}
				break;
			case 3:
				if($find_result['status']!=2){
					unset($up_where);
				}else{
					$up_where['status']=$status;
					$up_where['audit2_uid']=$this->login_id;
					$up_where['audit2_date']=date('Y-m-d H:i:s');
					$up_where['audit2_message']=$_REQUEST['audit_message'];
				}
				break;
		}
		if($_REQUEST['submit_info']){$up_where['submit_info']=$_REQUEST['submit_info'];}
		$data['status']=$db_audit_main->save($up_where);
		$data['state']=$_REQUEST['state'];
		echo json_encode($data);die;
	}
	
	//日程管理休息审核详情页 designed by:zhaoshihao 2017-12-05
	function schedule_xx_detail(){
		$db_schedule=M('db_schedule');
		$where['id']=$_REQUEST['id'];
		$data=$db_schedule->where($where)->find();
		//日期
		$db_schedule_detail=M('db_schedule_detail');
		$where_d['mid']=$_REQUEST['id'];
		$detail=$db_schedule_detail->where($where_d)->order('date')->select();
		foreach($detail as $key=>$val){
			if($key==0){
				$data['show_date']=$val['date'];
			}
			if(count($detail)!=1){
				if($key+1==count($detail)){
				$data['show_date'].='~'.$val['date'];
				}
			}
		}
		$fill_post_name=$this->get_db_universal_type(12,1,NULL,NULL,$data['fill_post']);
		$data['fill_post_name']=$fill_post_name['name2'];
		//项目
		$pd=$this->get_project($data['pid']);
		$data['project_num']=$pd['project_num'];
		$data['project_name']=$pd['project_name'];
		//工作类型
		$work_type_name=$this->get_db_universal_type(13,1,NULL,NULL,$data['work_type']);
		if(!empty($data)){
			$data['work_type_name']=$work_type_name['name3'];
			$data['work_name']=$work_type_name['name2'];
			$userd=$this->get_user($data['agent']);
			$data['agent_name']=$userd['username'];
			$data['position']=$userd['position_descr'];
			$data['mobilephone']=$userd['mobilephone'];
		}
		//休息审核
		$db_audit_main=M('db_audit_main');
		$where_m['audit_id']=$_REQUEST['id'];
		$where_m['type']=4;
		$audit=$db_audit_main->where($where_m)->find();
		$data['order_number']=$audit['order_number'];
		$data['audit_type']=$audit['audit_type'];
		$data['status']=$audit['status'];
		$data['audit_id']=$audit['id'];
		$data['arrive_status']=$audit['arrive_status'];
		$data['submit_info']=$audit['submit_info'];
		$data['dh_date']=$audit['dh_date'];
		$data['dh_message']=$audit['dh_message'];
		$data['dh_user']=$this->get_username($audit['dh_uid']);
		
		//审核人员
		$audit_user=$this->audit_user(4,$audit['audit_type']);
		foreach($audit_user as $kk=>$vv){
			if($audit['status']>$vv['audit_sort']){
				switch($vv['audit_name']){
					case '日程管理负责人':
						$audit_user[$kk]['audit_user']=$this->get_username($audit['audit2_uid']);
						$audit_user[$kk]['audit_date']=$audit['audit2_date'];
						$audit_user[$kk]['audit_comments']=$audit['audit2_message'];
					break;
				}
			}
			if(empty($vv['audit_uid']) and empty($audit_user[$kk]['audit_user'])){unset($audit_user[$kk]);}
		}
		//判断项目负责人是否离职
		$judge_user1_user=$this->get_user($pd['manager_uid']);
		if($judge_user1_user['status']!=1)
		{
			$pd['manager_name']=$pd['manager_name'].'(离职)';
		}
		$array1=array("audit_name"=>"项目负责人","audit_user"=>"".$pd['manager_name']."","audit_date"=>"".$audit['audit1_date']."","audit_comments"=>"".$audit['audit1_message']."","audit_sort"=>"1");
		array_unshift($audit_user,$array1);
		$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($audit['add_uid'])."","audit_date"=>"".$audit['add_date']."","audit_sort"=>"-1");
		array_unshift($audit_user,$array2);
		foreach($audit_user as $k1=>$v1){
			if($audit['arrive_status']==$v1['audit_sort']){
				$arrive_name=$v1['audit_name'];
				if($audit['arrive_status']=='-1'){$arrive_info=$audit['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
				$arrive_date=$v1['audit_date'];
			}
			if($audit['dh_status']==$v1['audit_sort']){
				$audit_user[$k1]['arrive_name']=$arrive_name;
				$audit_user[$k1]['dh_message']=$audit['dh_message'];
				$audit_user[$k1]['dh_date']=$audit['dh_date'];
				$audit_user[$k1]['arrive_info']=$arrive_info;
				$audit_user[$k1]['arrive_date']=$arrive_date;
			}
		}
		$this->assign('sum',count($audit_user));
		$this->assign('audit_user',$audit_user);
		$this->assign('state',$_REQUEST['state']);
		foreach($audit_user as $ka=>$va){
			if($data['status']<=$va['audit_sort']){
				unset($audit_user[$ka]);
			}
		}
		$this->assign('audit_list',$audit_user);
		//审核状态
		$audit_sh=$this->audit_type_next_person(4,$data['audit_type'],$data['status'],'egt');
		$audit_qs=$this->audit_type_next_person(4,$data['audit_type'],$data['status'],'lt');
		if($data['status']==1){
			if($pd['manager_uid']==$this->login_id){
				$shenhe=1;
			}
		}else{
			if($data['status']!=-1){
				if(in_array($this->login_id,explode(',',$audit_sh['audit_uid']))){$shenhe=1;}
			}
		}
		if($data['status']==2){
			if($pd['manager_uid']==$this->login_id){
				$qishen=1;
			}
		}else{
			if(in_array($this->login_id,explode(',',$audit_qs['audit_uid']))){$qishen=1;}
		}
		$this->assign('data',$data);
		$this->assign('audit',$audit);
		$this->assign('shenhe',$shenhe);
		$this->assign('qishen',$qishen);
		$this->display();
	}
	
	//营销计划管理 designed by:zhangsen 2017-11-14
	function project_plan_list(){
		parent::check_permission('YX');
		//查找
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		//审核状态
		if(!empty($_REQUEST['state'])){$state=$_REQUEST['state'];}else{$state=-10;}
		$this->assign('state',$state);
		$audit1=parent::bool_audit_list_user(2,'营销负责人');$this->assign('audit1',$audit1);//是否营销负责人
		$audit2=parent::bool_audit_list_user(2,'运营负责人');$this->assign('audit2',$audit2);//是否运营负责人
		$audit3=parent::bool_audit_list_user(2,'公司负责人');$this->assign('audit3',$audit3);//是否公司负责人
		if($audit1){$pa=1;}
		elseif($audit2){$pa=2;}
		elseif($audit3){$pa=3;}
		if(!empty($_REQUEST['pa'])){
			$pa=$_REQUEST['pa'];
		}
		$this->assign('pa',$pa);
		if($state==1)
		{
			$where_p['db_project_plan.status']=$pa;
			//审核流程
			$where_p['db_universal_audit.type']=2;
			switch($pa){
				case 1:
					$where_p['db_universal_audit.audit_name']='营销负责人';
				break;
				case 2:
					$where_p['db_universal_audit.audit_name']='运营负责人';
				break;
				case 3:
					$where_p['db_universal_audit.audit_name']='公司负责人';
				break;
			}
			$where_p['db_universal_audit.audit_user']=array('like',"%".$this->login_username."%");
		}
		elseif($state==2){
			if($pa==1)
			{
				$where_p['audit1_uid']=$this->login_id;
			}
			elseif($pa==2)
			{
				$where_p['audit2_uid']=$this->login_id;
			}
			elseif($pa==3)
			{
				$where_p['audit3_uid']=$this->login_id;
			}
			else
			{
				$where_p['db_project_plan.status']=NULL;
			}
		}else{
			if($pa==1)
			{
				$where_p['_string']="db_universal_audit.audit_name='营销负责人' or audit1_uid=".$this->login_id;
			}
			elseif($pa==2)
			{
				$where_p['_string']="db_universal_audit.audit_name='运营负责人' or audit2_uid=".$this->login_id;
			}
			elseif($pa==3)
			{
				$where_p['_string']="db_universal_audit.audit_name='公司负责人' or audit3_uid=".$this->login_id;
			}
			else
			{
				$where_p['db_project_plan.status']=NULL;
			}
		}
		if(get_permission('YX',1))
		{
			unset($where_p);
			if($state==1){
				$where_p['db_project_plan.status']=array('in','1,2,3');
			}elseif($state==2){
				$where_p['db_project_plan.status']=array('eq',4);
			}
		}
		//后续优化一人多权限
		/*
		else{
			$str1=NULL;
			$audit1=parent::bool_audit_list_user(2,'营销负责人');$this->assign('audit1',$audit1);//是否营销负责人
			$audit2=parent::bool_audit_list_user(2,'运营负责人');$this->assign('audit2',$audit2);//是否运营负责人
			$audit3=parent::bool_audit_list_user(2,'公司负责人');$this->assign('audit3',$audit3);//是否公司负责人
			if($state==1){
				if($audit1){
					$str1.="(db_project_plan.status=1 or (db_project_plan.status=2 and audit1_uid=".$this->login_id.")) or";
				}if($audit2){
					$str1.="(db_project_plan.status=2 or (db_project_plan.status=3 and audit2_uid=".$this->login_id.")) or";
				}if($audit3){
					$str1.="(db_project_plan.status=3 or (db_project_plan.status=4 and audit3_uid=".$this->login_id.")) or";
				}
			}elseif($state==2){
				if($audit1){
					$str1.="(db_project_plan.status=4 and audit1_uid=".$this->login_id.") or";
				}if($audit2){
					$str1.="(db_project_plan.status=4 and audit2_uid=".$this->login_id.") or";
				}if($audit3){
					$str1.="(db_project_plan.status=4 and audit3_uid=".$this->login_id.") or";
				}
			}else{
				if($audit1){
					$str1.="(db_project_plan.status=1 or (db_project_plan.status=2 and audit1_uid=".$this->login_id.") or (db_project_plan.status=4 and audit1_uid=".$this->login_id.")) or";
				}if($audit2){
					$str1.="(db_project_plan.status=2 or (db_project_plan.status=3 and audit2_uid=".$this->login_id.") or (db_project_plan.status=4 and audit2_uid=".$this->login_id.")) or";
				}if($audit3){
					$str1.="(db_project_plan.status=3 or (db_project_plan.status=4 and audit3_uid=".$this->login_id.") or (db_project_plan.status=4 and audit3_uid=".$this->login_id.")) or";
				}
			}
		}*/
		//查询项目
		$db_project=M('db_project');
		$db_project_plan=M('db_project_plan');
		if(!empty($keyword))
		{
			$map['db_project.project_num']=array('like','%'.$keyword.'%');
			$map['db_project.project_name']=array('like','%'.$keyword.'%');
			$map['_logic']='or';
			$where_p['_complex']=$map;
		}
		$count=$db_project_plan->join('Left Join db_project on db_project.id=db_project_plan.pid')->join('LEFT JOIN db_universal_audit ON db_project_plan.audit_type=db_universal_audit.audit_type')->where($where_p)->group('db_project_plan.id')->select(); 
		$Page = new \Think\Page(count($count),C('PAGE_LIST_ROWS')); 
		$show=$Page->show(); 
		$result=$db_project_plan->field('db_project_plan.*,db_project.project_num,db_project.project_name,db_project.manager_uid')->join('Left Join db_project on db_project.id=db_project_plan.pid')->join('LEFT JOIN db_universal_audit ON db_project_plan.audit_type=db_universal_audit.audit_type')->where($where_p)->group('db_project_plan.id')->limit($Page->firstRow.','.$Page->listRows)->order('db_project_plan.id desc')->select();
		foreach($result as $key=>$val)
		{	
			if($val['status']==1 || $val['status']==2 || $val['status']==3){
				$audit_user=$this->audit_type_next(2,$val['audit_type'],$val['status']);
			}
			$result[$key]['audit_user']=$audit_user['audit_user'];
			$result_type=$this->get_db_universal_type(8,1,NULL,NULL,NULL,$val['type']);
			$result[$key]['type_name']=$result_type['name1'];
			$file_url=explode(',',$val['file_url']);
			$file_name=explode(',',$val['file_name']);
			$result[$key]['file_url']=$file_url;
			$result[$key]['file_name']=$file_name;
			$result[$key]['add_user']=$this->get_username($val['add_uid']);
			$result_next=0;
			
			//审核流程
			$result[$key]['audit_user']=$audit_user['audit_user'];
			//审核人员
			$audit_arr=$this->audit_user(2,$val['audit_type']);
			foreach($audit_arr as $kk=>$vv){
				if($val['status']>$vv['audit_sort']){
					switch($vv['audit_name']){
						case '营销负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($val['audit1_uid']);
							$audit_arr[$kk]['audit_date']=$val['audit1_date'];
							$audit_arr[$kk]['audit_comments']=$val['audit1_message'];
						break;
						case '运营负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($val['audit2_uid']);
							$audit_arr[$kk]['audit_date']=$val['audit2_date'];
							$audit_arr[$kk]['audit_comments']=$val['audit2_message'];
						break;
						case '公司负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($val['audit3_uid']);
							$audit_arr[$kk]['audit_date']=$val['audit3_date'];
							$audit_arr[$kk]['audit_comments']=$val['audit3_message'];
						break;
					}
				}
				if(((empty($vv['audit_uid'])) and (empty($audit_arr[$kk]['audit_date']))) or ((empty($audit_arr[$kk]['audit_user'])) and (empty($audit_arr[$kk]['audit_date'])))){unset($audit_arr[$kk]);}
				
				if($val['status']==4 and (empty($audit_arr[$kk]['audit_date']))){unset($audit_arr[$kk]);}
			}
			$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($val['post_uid'])."","audit_date"=>"".$val['post_date']."","audit_sort"=>"-1");
			array_unshift($audit_arr,$array2);
			foreach($audit_arr as $k1=>$v1){
				if($val['arrive_status']==$v1['audit_sort']){
					$arrive_name=$v1['audit_name'];
					if($val['arrive_status']=='-1'){$arrive_info=$val['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
					$arrive_date=$v1['audit_date'];
				}
				if($val['dh_status']==$v1['audit_sort']){
					$audit_arr[$k1]['arrive_name']=$arrive_name;
					$audit_arr[$k1]['dh_message']=$val['back_to_resaon'];
					$audit_arr[$k1]['dh_date']=$val['back_date'];
					$audit_arr[$k1]['arrive_info']=$arrive_info;
					$audit_arr[$k1]['arrive_date']=$arrive_date;
				}
			}
			$result[$key]['audit_arr']=$audit_arr;
			//后续优化一人多权限
			/*
			//审核
			$audit_sh=$this->audit_type_next_person(2,$val['audit_type'],$val['status'],'egt');
			$audit_qs=$this->audit_type_next_person(2,$val['audit_type'],$val['status'],'lt');
			if(in_array($this->login_id,explode(',',$audit_sh['audit_uid']))){$result[$key]['shenhe']=1;}
			if(in_array($this->login_id,explode(',',$audit_qs['audit_uid']))){$result[$key]['qishen']=1;}
			*/
		}
		$this->assign('result',$result);
		$this->assign('page',$show);
		$this->display();
	}
	
	//任务管理 designed by:zhangsen 2017-12-28
	function task_list(){
		//查找
		$type1=I('type1',-10);
		$this->assign('type1',$type1);
		$type2=I('type2',-10);
		$this->assign('type2',$type2);
		//分类筛选
		$type1_list=$this->library_type_list(18,NULL,NULL,1);
		$this->assign('type1_list',$type1_list);
		foreach($type1_list as $key=>$value){
			if($type1==$value['id']){
				$type2_list=$value['second'];
				$this->assign('type2_list',$type2_list);
			}
		}
		$db_task=M('db_task');
		$db_task_detail=M('db_task_detail');
		$where['db_audit_main.type']=5;
		if($_REQUEST['pid']){
			//项目详情
			$project=parent::get_project($_REQUEST['pid']);
			$this->assign('project',$project);
			$this->assign('project_bg',$this->get_project_bg($_REQUEST['pid']));
			$where['db_audit_main.pid']=$_REQUEST['pid'];
			$where['db_task.work_type']=2;
		}else{
			$where_d['uid']=$this->login_id;
			$result_d=$db_task_detail->field('mid')->where($where_d)->select();
			foreach($result_d as $key=>$value){
				$mid_str.=$value['mid'].',';
			}
			if($mid_str){
				$where['_string']="db_task.id in (".rtrim($mid_str,',').") or db_task.head_uid='".$this->login_id."' or db_audit_main.add_uid='".$this->login_id."'";
			}
			else{
				$where['_string']=" db_task.head_uid='".$this->login_id."' or db_audit_main.add_uid='".$this->login_id."'";
			}
		}
		if($type1!=-10){$where['type1']=$type1;}
		if($type2!=-10){$where['type2']=$type2;}
		$count=$db_task->join('db_audit_main on db_task.id=db_audit_main.audit_id')->where($where)->count();
		$Page = new \Think\Page($count,15);
		$show=$Page->show();
		$result=$db_task->field('db_audit_main.order_number,db_audit_main.status,db_audit_main.add_uid,db_audit_main.add_date,db_audit_main.id as tid,db_task.*')->join('db_audit_main on db_task.id=db_audit_main.audit_id')->where($where)->order('add_date desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($result as $key=>$value){
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['head_user']=$this->get_username($value['head_uid']);
			$where_dm['mid']=$value['id'];
			$result_dm=$db_task_detail->where($where_dm)->select();
			$ct=0;
			foreach($result_dm as $k=>$v){
				if($v['status']==-1){$ct++;}
			}
			$result[$key]['ct']=$ct;
			$result[$key]['result_d']=$result_dm;
		}
		$this->assign('pid',$_REQUEST['pid']);
		$this->assign('page',$show);
		$this->assign('result',$result);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//任务管理-->添加 designed by:zhangsen 2017-12-28
	function task_add(){
		//类别1筛选
		$type1_list=$this->library_type_list(18,NULL,NULL,1);
		$this->assign('type1_list',$type1_list);
		if($_REQUEST['action']=='add'){
			$db_task=M('db_task');
			if($_REQUEST['pid']){
				$where_t['work_type']=2;
			}else{
				$where_t['work_type']=1;
			}
			$where_t['type1']=$_REQUEST['type1'];
			$where_t['type2']=$_REQUEST['type2'];
			$where_t['type3']=$_REQUEST['type3'];
			$where_t['type1_other']=$_REQUEST['type1_other']?$_REQUEST['type1_other']:NULL;
			$where_t['type2_other']=$_REQUEST['type2_other']?$_REQUEST['type2_other']:NULL;
			$where_t['type3_other']=$_REQUEST['type3_other']?$_REQUEST['type3_other']:NULL;
			$where_t['head_uid']=$_REQUEST['head_uid'];
			$where_t['name']=$_REQUEST['name'];
			$where_t['supervision']=$_REQUEST['supervision'];
			$where_t['start_date']=$_REQUEST['start_date'];
			$where_t['end_date']=$_REQUEST['end_date'];
			foreach($_REQUEST['file_name'] as $key=>$value){
				if(!empty($value)){
					$file_name.=$value.',';
				}
			}
			foreach($_REQUEST['file_url'] as $key=>$value){
				if(!empty($value)){
					$file_url.=$value.',';
				}
			}
			$where_t['file_name']=rtrim($file_name,',')?rtrim($file_name,','):NULL;
			$where_t['file_url']=rtrim($file_url,',')?rtrim($file_url,','):NULL;
			$where_t['remark']=$_REQUEST['remark'];
			$audit_id=$db_task->add($where_t);
			//添加
			$project=parent::get_project($_REQUEST['pid']);
			$db_audit_main=M('db_audit_main');
			$where_j_n['order_number']=array('like','RW'.date('Ymd').'%');
			$judge_num=$db_audit_main->field('order_number')->where($where_j_n)->order('id desc')->select();
			if(empty($judge_num))
			{
				$num='001';
			}
			else
			{
				$num=substr($judge_num[0]['order_number'],10,3)+1;
				if(strlen($num)==1){$num='00'.$num;}
				elseif(strlen($num)==2){$num='0'.$num;}
			}
			$where_a['order_number']='RW'.date('Ymd').$num;
			$where_a['pid']=$_REQUEST['pid']!=-10?$_REQUEST['pid']:NULL;
			$where_a['audit_id']=$audit_id;
			$where_a['audit_type']=$project['center_id'];
			$where_a['main_demand']=$_REQUEST['text_hid'];
			$where_a['status']=-1;
			$where_a['type']=5;
			$where_a['add_uid']=$this->login_id;
			$where_a['add_date']=date('Y-m-d H:i:s');
			$db_audit_main->add($where_a);
			$this->success("操作成功",__APP__."/Index/task_list/pid/".$_REQUEST['pid']);die;
		}
		$this->assign('pid',$_REQUEST['pid']);
		//项目详情
		$project=parent::get_project($_REQUEST['pid']);
		$this->assign('project',$project);
		$this->assign('project_bg',$this->get_project_bg($_REQUEST['pid']));
		//人员下拉菜单
		$this->assign('user_list',$this->get_all_username());
		$this->display();
	}
	
	//任务管理-->编辑 designed by:zhangsen 2017-12-28
	function task_edit(){
		$db_task=M('db_task');
		$where_t['id']=$_REQUEST['id'];
		$result=$db_task->where($where_t)->find();
		//类别1筛选
		$type1_list=$this->library_type_list(18,NULL,NULL,1);
		$this->assign('type1_list',$type1_list);
		foreach($type1_list as $key=>$value){
			if($result['type1']==$value['id']){
				$type2_list=$value['second'];
				$this->assign('type2_list',$type2_list);
				foreach($type2_list as $kk=>$vv){
					if($result['type2']==$vv['id']){
						$type3_list=$vv['third'];
						$this->assign('type3_list',$type3_list);
					}
				}
			}
		}
		if($result['file_url']){$file_url_str=explode(',',$result['file_url']);}
		if($result['file_name']){$file_name_str=explode(',',$result['file_name']);}
		$result['file_url']=$file_url_str;
		$result['file_name']=$file_name_str;
		if($result['work_type']==2){
			$db_audit_main=M('db_audit_main');
			$where_m['audit_id']=$result['id'];
			$result_m=$db_audit_main->where($where_m)->find();
			$result['pid']=$result_m['pid'];
		}
		$this->assign('result',$result);
		if($_REQUEST['action']=='edit'){
			foreach($_REQUEST['file_name'] as $key=>$value){
				if(!empty($value)){
					$file_name.=$value.',';
				}
			}
			foreach($_REQUEST['file_url'] as $key=>$value){
				if(!empty($value)){
					$file_url.=$value.',';
				}
			}
			$where_t['type1']=$_REQUEST['type1'];
			$where_t['type2']=$_REQUEST['type2'];
			$where_t['type3']=$_REQUEST['type3'];
			$where_t['type1_other']=$_REQUEST['type1_other']?$_REQUEST['type1_other']:NULL;
			$where_t['type2_other']=$_REQUEST['type2_other']?$_REQUEST['type2_other']:NULL;
			$where_t['type3_other']=$_REQUEST['type3_other']?$_REQUEST['type3_other']:NULL;
			$where_t['head_uid']=$_REQUEST['head_uid'];
			$where_t['file_name']=rtrim($file_name,',')?rtrim($file_name,','):NULL;
			$where_t['file_url']=rtrim($file_url,',')?rtrim($file_url,','):NULL;
			$where_t['name']=$_REQUEST['name'];
			$where_t['supervision']=$_REQUEST['supervision'];
			$where_t['start_date']=$_REQUEST['start_date'];
			$where_t['end_date']=$_REQUEST['end_date'];
			$where_t['remark']=$_REQUEST['remark'];
			$db_task->save($where_t);
			$this->success("操作成功",__APP__."/Index/task_list/pid/".$_REQUEST['pid']."&p=".$_SESSION['page']);die;
		}
		$this->assign('pid',$_REQUEST['pid']);
		//项目详情
		$project=parent::get_project($_REQUEST['pid']);
		$this->assign('project',$project);
		$this->assign('project_bg',$this->get_project_bg($_REQUEST['pid']));
		//人员下拉菜单
		$this->assign('user_list',$this->get_all_username());
		$this->display();
	}
	
	//任务管理-->详情 designed by:zhangsen 2017-12-28
	function task_detail(){
		$db_task=M('db_task');
		$where['db_task.id']=$_REQUEST['id'];
		$where['db_audit_main.type']=5;
		$result=$db_task->field('db_task.*,db_audit_main.*,db_task.id as tid')->join('db_audit_main on db_task.id=db_audit_main.audit_id')->where($where)->find();
		$result['add_user']=$this->get_username($result['add_uid']);
		if($result['file_url']){$file_url_str=explode(',',$result['file_url']);}
		if($result['file_name']){$file_name_str=explode(',',$result['file_name']);}
		$result['file_url']=$file_url_str;
		$result['file_name']=$file_name_str;
		if($result['file_url_c']){$file_url_c_str=explode(',',$result['file_url_c']);}
		if($result['file_name_c']){$file_name_c_str=explode(',',$result['file_name_c']);}
		$result['file_url_c']=$file_url_c_str;
		$result['file_name_c']=$file_name_c_str;
		$project=$this->get_project($result['pid']);
		$result['project_num']=$project['project_num'];
		$result['project_name']=$project['project_name'];
		$result['dh_user']=$this->get_username($result['dh_uid']);
		$db_universal_label1=M('db_universal_label1');
		$db_universal_label2=M('db_universal_label2');
		$db_universal_label3=M('db_universal_label3');
		//任务分类
		$where_t1['id']=$result['type1'];
		$name_t1=$db_universal_label1->where($where_t1)->find();
		$result['type1_name']=$name_t1['first_name'];
		//任务子类
		$where_t2['id']=$result['type2'];
		$name_t2=$db_universal_label2->where($where_t2)->find();
		$result['type2_name']=$name_t2['second_name'];
		//任务子类
		$where_t3['id']=$result['type3'];
		$name_t3=$db_universal_label3->where($where_t3)->find();
		$result['type3_name']=$name_t3['third_name'];
		$result['head_user']=$this->get_username($result['head_uid']);
		////
		//审核人员
		$audit_arr=$this->audit_user(5,$result['audit_type']);
		foreach($audit_arr as $kk=>$vv){
			if($result['status']>$vv['audit_sort']){
				switch($vv['audit_name']){
					case '审核人':
						$audit_arr[$kk]['audit_user']=$this->get_username($result['audit1_uid']);
						$audit_arr[$kk]['audit_date']=$result['audit1_date'];
						$audit_arr[$kk]['audit_comments']=$result['audit1_message'];
					break;
					case '审批人':
						$audit_arr[$kk]['audit_user']=$this->get_username($result['audit2_uid']);
						$audit_arr[$kk]['audit_date']=$result['audit2_date'];
						$audit_arr[$kk]['audit_comments']=$result['audit2_message'];
					break;
				}
			}
			if(empty($vv['audit_uid']) and empty($audit_arr[$kk]['audit_user'])){unset($audit_arr[$kk]);}
		}
		$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($result['post_uid'])."","audit_date"=>"".$result['post_date']."","audit_sort"=>"-1");
		array_unshift($audit_arr,$array2);
		foreach($audit_arr as $k1=>$v1){
			if($result['arrive_status']==$v1['audit_sort']){
				$arrive_name=$v1['audit_name'];
				if($result['arrive_status']=='-1'){$arrive_info=$result['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
				$arrive_date=$v1['audit_date'];
			}
			if($result['dh_status']==$v1['audit_sort']){
				$audit_arr[$k1]['arrive_name']=$arrive_name;
				$audit_arr[$k1]['dh_message']=$result['dh_message'];
				$audit_arr[$k1]['dh_date']=$result['dh_date'];
				$audit_arr[$k1]['arrive_info']=$arrive_info;
				$audit_arr[$k1]['arrive_date']=$arrive_date;
			}
		}
		$this->assign('audit_user',$audit_arr);
		foreach($audit_arr as $ka=>$va){
			if($result['status']<=$va['audit_sort']){
				unset($audit_arr[$ka]);
			}
		}
		$this->assign('audit_list',$audit_arr);
		$audit_sh=$this->audit_type_next_person(5,$result['audit_type'],$result['status'],'egt');
		$audit_qs=$this->audit_type_next_person(5,$result['audit_type'],$result['status'],'lt');
		if(in_array($this->login_id,explode(',',$audit_sh['audit_uid']))){$shenhe=1;}
		if(in_array($this->login_id,explode(',',$audit_qs['audit_uid']))){$qishen=1;}
		$this->assign('shenhe',$shenhe);
		$this->assign('qishen',$qishen);
		$this->assign('result',$result);
		$db_task_detail=M('db_task_detail');
		$where_d['mid']=$_REQUEST['id'];
		$result_d=$db_task_detail->where($where_d)->select();
		$ct=0;
		foreach($result_d as $key=>$value){
			if($value['status']==-1){$ct++;}
			$result_d[$key]['username']=$this->get_username($value['uid']);
		}
		$this->assign('ct',$ct);
		$this->assign('result_d',$result_d);
		//姓名下拉菜单
		if($result['work_type']==2){
			$project=parent::get_project($result['pid']);
			if($project['center_id']==130005 and empty($project['info_id'])){
				$db_project_user=M('db_project_user');
				$where_p['pid']=$result['pid'];
				$where_p['db_user.status']=1;
				$user_list=$db_project_user->field('db_project_user.*,db_user.username')->join('db_user on db_project_user.uid=db_user.id')->where($where_p)->order('spell desc')->group('uid')->select();
				foreach($user_list as $key=>$value){
					$user_list[$key]['username']=$value['username'];
					$user_list[$key]['id']=$value['uid'];
				}
			}else{
				$project_bg=$this->get_project_bg($result['pid']);
				$use=array();
				$use[]=$project['manager_uid'];
				$use[]=$project['director_uid'];
				foreach(explode(',',$project_bg['project_uids']) as $ka=>$va){
					$use[]=$va;
				}
				$use=array_flip(array_flip($use));
				$use=join(',',$use);
				$user_list=$this->get_all_username(1,NULL,NULL,NULL,$use);
			}
		}else{
			$user_list=$this->get_all_username(1,$this->login_center_id,NULL,NULL,NULL);
		}
		$this->assign('user_list',$user_list);
		$this->assign('audit',$_REQUEST['audit']);
		$this->assign('pid',$_REQUEST['pid']);
		//项目详情
		$project=parent::get_project($_REQUEST['pid']?$_REQUEST['pid']:$result['pid']);
		$this->assign('project',$project);
		$this->assign('project_bg',$this->get_project_bg($_REQUEST['pid']));
		$this->display();
	}
	
	//任务管理-->ajax designed by:zhangsen 2017-12-28
	function task_ajax(){
		if($_REQUEST['action']=='delete')
		{
			$db_task=M('db_task');
			$db_audit_main=M('db_audit_main');
			$db_task_detail=M('db_task_detail');
			$where_de['id']=$_REQUEST['id'];
			$db_task->where($where_de)->delete();
			$where_del['audit_id']=$_REQUEST['id'];
			$result_bool=$db_audit_main->where($where_del)->delete();
			$where_deld['mid']=$_REQUEST['id'];
			$result_bool=$db_task_detail->where($where_deld)->delete();
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='add_user')
		{
			$db_task_detail=M('db_task_detail');
			$where['mid']=$_REQUEST['mid'];
			$where['uid']=$_REQUEST['uid'];
			$where['note']=$_REQUEST['note'];
			$where['end_date']=$_REQUEST['end_date'];
			$where['status']=-1;
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_task_detail->add($where);
			if($result_bool)
			{
				$project=$this->get_project($_REQUEST['pid']);
				$user=$this->get_user($_REQUEST['uid']);
				$db_task=M('db_task');
				$db_universal_label1=M('db_universal_label1');
				$db_universal_label2=M('db_universal_label2');
				$where_t['id']=$_REQUEST['mid'];
				$task_result=$db_task->where($where_t)->find();
				//任务分类
				$where_t1['id']=$task_result['type1'];
				$name_t1=$db_universal_label1->where($where_t1)->find();
				$alert_type1=$name_t1['first_name'];
				//任务子类
				$where_t2['id']=$task_result['type2'];
				$name_t2=$db_universal_label2->where($where_t2)->find();
				$alert_type2=$name_t2['second_name'];
				$alert_type=$alert_type1.'-'.$alert_type2;
                $to_user['id']=$user['id'];
                $to_user['username']=$user['username'];
                $to_users_array[]=$to_user;
                $db_audit_main=M('db_audit_main');
                $where_task['audit_id']=$task_result['id'];
                $where_task['pid']=$project['id'];
                $find_result=$db_audit_main->where($where_task)->find();
                $this->alert_send('任务提醒',$to_users_array,'任务单号:'.$find_result['order_number']);
				if($user['openid']){
					$this->send_task_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Project/task_detail/id/'.$_REQUEST['mid'].'&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的项目任务，请及时查看。',$project['project_num'],$project['project_name'],$alert_type,NULL,'该任务截止日期为'.$_REQUEST['end_date'].'，请及时到系统查看完成，谢谢。');
				}
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='edit_user')
		{
			$db_task_detail=M('db_task_detail');
			$where['id']=$_REQUEST['id'];
			$where['uid']=$_REQUEST['uid'];
			$where['note']=$_REQUEST['note'];
			$where['end_date']=$_REQUEST['end_date'];
			$result_bool=$db_task_detail->save($where);
			if($result_bool)
			{
				$project=$this->get_project($_REQUEST['pid']);
				$user=$this->get_user($_REQUEST['uid']);
				$db_task=M('db_task');
				$db_universal_label1=M('db_universal_label1');
				$db_universal_label2=M('db_universal_label2');
				$where_t['id']=$_REQUEST['mid'];
				$task_result=$db_task->where($where_t)->find();
				//任务分类
				$where_t1['id']=$task_result['type1'];
				$name_t1=$db_universal_label1->where($where_t1)->find();
				$alert_type1=$name_t1['first_name'];
				//任务子类
				$where_t2['id']=$task_result['type2'];
				$name_t2=$db_universal_label2->where($where_t2)->find();
				$alert_type2=$name_t2['second_name'];
				$alert_type=$alert_type1.'-'.$alert_type2;
                $to_user['id']=$user['id'];
                $to_user['username']=$user['username'];
                $to_users_array[]=$to_user;
                $db_audit_main=M('db_audit_main');
                $where_task['audit_id']=$task_result['id'];
                $where_task['pid']=$project['id'];
                $find_result=$db_audit_main->where($where_task)->find();
                $this->alert_send('任务提醒',$to_users_array,'任务单号:'.$find_result['order_number']);
				if($user['openid']){
					$this->send_task_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Project/task_detail/id/'.$_REQUEST['mid'].'&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的项目任务，请及时查看。',$project['project_num'],$project['project_name'],$alert_type,NULL,'该任务截止日期为'.$_REQUEST['end_date'].'，请及时到系统查看完成，谢谢。');
				}
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='submit_file')
		{
			$db_task_detail=M('db_task_detail');
			$where['id']=$_REQUEST['mid'];
			$where['file_url']=$_REQUEST['file_url'];
			$where['file_name']=$_REQUEST['file_name'];
			$result_bool=$db_task_detail->save($where);
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='delete_file')
		{
			$db_task_detail=M('db_task_detail');
			$where['id']=$_REQUEST['id'];
			$where['file_url']=NULL;
			$where['file_name']=NULL;
			$result_bool=$db_task_detail->save($where);
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='delete_user')
		{
			$db_task_detail=M('db_task_detail');
			$where['id']=$_REQUEST['id'];
			$result_bool=$db_task_detail->where($where)->delete();
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='end_user')
		{
			$db_task_detail=M('db_task_detail');
			$where['id']=$_REQUEST['mid'];
			$where['score']=$_REQUEST['score'];
			$where['score_comments']=$_REQUEST['score_comments'];
			$where['status']=1;
			$result_bool=$db_task_detail->save($where);
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='submit_task')
		{
			$db_task=M('db_task');
			$where['id']=$_REQUEST['mid'];
			$where['conclusion']=$_REQUEST['conclusion'];
			foreach($_REQUEST['file_name'] as $key=>$value){
				if(!empty($value)){
					$file_name.=$value.',';
				}
			}
			foreach($_REQUEST['file_url'] as $key=>$value){
				if(!empty($value)){
					$file_url.=$value.',';
				}
			}
			$where['file_name_c']=rtrim($file_name,',')?rtrim($file_name,','):NULL;
			$where['file_url_c']=rtrim($file_url,',')?rtrim($file_url,','):NULL;
			$db_task->save($where);
			$db_audit_main=M('db_audit_main');
			$where_m['audit_id']=$_REQUEST['mid'];
			$where_m['type']=5;
			$where_save['flow_status']=1;
			if($find_result['flow_status']==-1){
				if($find_result['status']==$find_result['arrive_status']){
					$where_save['status']=$find_result['dh_status'];
				}
			}else{
				$where_save['status']=1;
			}
			$where_save['post_uid']=$this->login_id;
			$where_save['post_date']=date('Y-m-d H:i:s');
			$result_bool=$db_audit_main->where($where_m)->save($where_save);
			//发送提醒
			$where_f['audit_id']=$_REQUEST['mid'];
			$where_f['type']=5;
			$find_result=$db_audit_main->where($where_f)->find();
			$user_f=$this->get_user($find_result['add_uid']);
			$find_result['add_user']=$user_f['username'];
			if($find_result['flow_status']==-1){
				$sta=$this->audit_type_next_person(5,$find_result['audit_type'],$find_result['dh_status'],'egt');
			}else{
				$sta=$this->audit_type_next_person(5,$find_result['audit_type'],-1,'egt');
			}
			$audit_arr=explode(',',$sta['audit_uid']);
			foreach($audit_arr as $key=>$value){
				$user=$this->get_user($value);
                $to_user['id']=$user['id'];
                $to_user['username']=$user['username'];
                $to_users_array[]=$to_user;
                $this->alert_send('任务管理审核流程',$to_users_array,'申请单编号:'.$find_result['order_number']);
				if($user['openid']){
					$this->send_audit_notice($user['openid'],'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9104bb1d0267056&redirect_uri=http://ko.joyuti.com/dms_erp/index.php?s=Mobile/Project/task_detail/id/'.$find_result['audit_id'].'/audit/sh&response_type=code&scope=snsapi_base&state=1#wechat_redirect','您有新的审核流程，请及时处理。','任务管理','申请单号【'.$find_result['order_number'].'】',$find_result['add_user'],substr($find_result['add_date'],0,10),NULL);
				}
			}
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='type2_list')
		{
			$type1=$_REQUEST['type1'];
			$type1_list=$this->library_type_list(18,NULL,NULL,1);
			foreach($type1_list as $key=>$value){
				if($type1==$value['id']){
					$type2_list=$value['second'];
				}
			}
			if($type2_list)
			{
				$data['status']=self::YES;
				$data['data']=$type2_list;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='type3_list')
		{
			$type1=$_REQUEST['type1'];
			$type2=$_REQUEST['type2'];
			$type1_list=$this->library_type_list(18,NULL,NULL,1);
			foreach($type1_list as $key=>$value){
				if($type1==$value['id']){
					$type2_list=$value['second'];
					foreach($type2_list as $kk=>$vv){
						if($type2==$vv['id']){
							$type3_list=$vv['third'];
						}
					}
				}
			}
			if($type3_list)
			{
				$data['status']=self::YES;
				$data['data']=$type3_list;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
	}
	
	//公共方法-->标签管理 designed by:zhaoshihao 2016-11-09
	function label_administration(){
		//数据反选start
		$login_center_id=$this->login_center_id;
		$this->assign('login_center_id',$login_center_id);
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		//筛选判断
		$screen=$this->library_type_list($_REQUEST['classif']);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		$db_library_main=M('db_library_main');
		$where['db_library_main.type']=$_REQUEST['type'];
		//排序
		$order_str="db_library_main.add_date desc";
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
		}
		if($_REQUEST['type']==5){
			$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct,db_user.username,db_user.mobilephone,db_user.user_number')->where($where)->join('left join db_user on db_library_main.name=db_user.id')->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order('rank_id desc')->select();
		}else{
			$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->select();
		}
		if($_REQUEST['type']==5){
			foreach($result as $key=>$value)
			{
				$result[$key]['name']=$value['username'];
			}
		}
		$this->assign('result',$result);
		//数据反选end
		$db_universal_label1=M('db_universal_label1');
		$db_universal_label2=M('db_universal_label2');
		$db_universal_label_type=M('db_universal_label_type');
		$db_user=M('db_user');
		$db_project_bg=M('db_project_bg');
		$db_project_uploads=M('db_project_uploads');
		$where_keyword['classif']=array('in',$_REQUEST['classif']);
		$where_keyword['first_name']=array('exp','is not NULL');
		if(!empty($_REQUEST['fcenter_id'])){$where_keyword['fcenter_id']=$_REQUEST['fcenter_id'];}
		$all_keywords=$db_universal_label1->field('id,first_name')->where($where_keyword)->order('classif,first_sort')->select();
		//一级循环
		foreach($all_keywords as $key=>$value){
			$where_second['first_id']=$value['id'];
			$where_second['second_name']=array('neq','全部');
			$all_keywords[$key]['second']=$db_universal_label2->field('id,second_name')->where($where_second)->order('second_sort')->select();
			$all_keywords[$key]['sum']=count($all_keywords[$key]['second']);
			//二级循环
			foreach($all_keywords[$key]['second'] as $k1=>$v1){
				//根据一级判断
				unset($where_judge);
				$kk++;
				$all_keywords[$key]['second'][$k1]['kk']=$kk;
				if(($_REQUEST['classif']==1) || ($_REQUEST['classif']==4) || ($_REQUEST['classif']==9) || ($_REQUEST['classif']==10) || ($_REQUEST['classif']==11) || ($_REQUEST['classif']==12) || ($_REQUEST['classif']==14)){
					$where_judge['_string']='find_in_set("'.$v1['id'].'",sort_id)';
					$judge_result=$db_universal_label_type->where($where_judge)->find();
				}elseif($_REQUEST['classif']=='2,5,8'){
					if($value['id']==8){
						$where_judge['_string']='find_in_set("'.$v1['id'].'",position_id)';
						$judge_result=$db_user->where($where_judge)->find();
					}else{
						$where_judge['_string']='find_in_set("'.$v1['id'].'",department_id)';
						$judge_result=$db_user->where($where_judge)->find();
					}
				}elseif($_REQUEST['classif']==6){
					if($value['id']==22){
						$where_judge['_string']='find_in_set("'.$v1['id'].'",p_type)';
						$judge_result=$db_project_bg->where($where_judge)->find();
					}elseif($value['id']==23){
						$where_judge['_string']='find_in_set("'.$v1['id'].'",business_type)';
						$judge_result=$db_project_bg->where($where_judge)->find();
					}elseif($value['id']==24){
						$where_judge['_string']='find_in_set("'.$v1['id'].'",type)';
						$judge_result=$db_project_uploads->where($where_judge)->find();
					}
				}
				if(empty($judge_result))
				{
					$all_keywords[$key]['second'][$k1]['bool']=1;
				}
			}
		}
		if(empty($all_keywords[0]['first_name'])){$all_keywords=NULL;}
		if($_REQUEST['classif']=='2,5,8'){
			$this->assign('classif',5);
		}else{
			$this->assign('classif',$_REQUEST['classif']);
		}
		$this->assign('type',$_REQUEST['type']);
		$this->assign('types',$_REQUEST['types']);
		$this->assign('fcenter_id',$_REQUEST['fcenter_id']);
		$this->assign('all_keywords',$all_keywords);
		$this->assign('sum',count($all_keywords));
		$this->assign('sum_s',count($all_keywords[0]['second']));
		$this->assign('sz',$_REQUEST['sz']);
		if($_REQUEST['sz']==1){
			//功能开关
			$db_universal_type=M('db_universal_type');
			$where_c['type']=10;
			$where_c['name1']=$_REQUEST['type'];
			$sz_status=$db_universal_type->where($where_c)->find();
			$this->assign('sz_status',$sz_status);
			//共享文件夹
			$db_library_share=M('db_library_share');
			$where_sh['folder_name']=array('exp','is not NULL');
			$where_sh['folder_type']=$_REQUEST['type'];
			$share=$db_library_share->where($where_sh)->select();
			foreach($share as $ks=>$vs){
				$where_m['id']=array('in',$vs['mid']);
				$share[$ks]['detail']=$db_library_main->where($where_m)->select();
				foreach($share[$ks]['detail'] as $ka=>$va){
					if($va['type']==5){
						$share[$ks]['detail'][$ka]['name']=$this->get_username($va['name']);
					}
				}
			}
			$this->assign('share',$share);
			//选择用户下拉菜单
			$this->assign("user_list",$this->get_all_department());
		}
		$this->display();
	}
	
	//公共方法-->标签管理-->传值 designed by:zhaoshihao 2016-11-09
	function label_administration_status(){
		$db_universal_label1=M('db_universal_label1');
		$db_universal_label2=M('db_universal_label2');
		if($_REQUEST['labels']==1){
			//获取一级分类
			if($_REQUEST['classif']==5){
				$where_keyword['classif']=array('in','2,5,8');
			}else{
				$where_keyword['classif']=$_REQUEST['classif'];
			}
			if(!empty($_REQUEST['fcenter_id'])){$where_keyword['fcenter_id']=$_REQUEST['fcenter_id'];}
			$data=$db_universal_label1->field('id,first_name as name')->where($where_keyword)->order('first_sort')->select();
		}elseif($_REQUEST['labels']==2){
			//获取排序的数组
			$where_keyword['first_id']=$_REQUEST['fid'];
			$where_keyword['second_name']=array('neq','全部');
			$data=$db_universal_label2->field('id,second_name as name')->where($where_keyword)->order('second_sort')->select();
		}elseif($_REQUEST['labels']==3){
			//获取该一级分类下的二级分类
			$where['id']=$_REQUEST['id'];
			$second=$db_universal_label2->where($where)->find();
			$where_keyword['first_id']=$second['first_id'];
			$where_keyword['id']=array('neq',$_REQUEST['id']);
			$where_keyword['second_name']=array('neq','全部');
			$data=$db_universal_label2->where($where_keyword)->order('second_sort')->select();
		}elseif($_REQUEST['action']=='fx_detail'){
			//文件夹编辑弹出
			$db_library_share=M('db_library_share');
			$where_s['id']=$_REQUEST['mid'];
			$share=$db_library_share->where($where_s)->find();
			$shar=explode(',',$share['mid']);
			$db_library_main=M('db_library_main');
			$where['db_library_main.type']=$share['folder_type'];
			//排序
			$order_str="db_library_main.add_date desc";
			$ids_str=NULL;
			foreach($screen as $kk=>$vv)
			{
				$qb_id=NULL;
				foreach($vv['second'] as $kkk=>$vvv)
				{
					if($vvv['second_name']=='全部')
					{
						$qb_id=$vvv['id'];
					}
				}
				if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
				$first_sort[]=$value['id'];
			}
			if($_REQUEST['folder_type']==5){
				$data=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct,db_user.username,db_user.mobilephone,db_user.user_number')->where($where)->join('left join db_user on db_library_main.name=db_user.id')->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order('rank_id desc')->select();
			}else{
				$data=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->select();
			}
			if($_REQUEST['folder_type']==5){
				foreach($data as $key=>$value)
				{
					$data[$key]['name']=$value['username'];
				}
			}
			foreach($data as $key=>$val){
				foreach($shar as $kk=>$vv){
					if($vv==$val['id']){
						$data[$key]['checked']=1;
					}
				}
			}
		}
		echo json_encode($data);die;
	}
	
	//公共方法-->标签管理-->数据反选 designed by:zhaoshihao 2016-11-09
	function label_administration_data(){
		$center_id=I('center_id',-10);
		$this->assign('center_id',$center_id);
		$ids_array=explode(',',$_REQUEST['ids']);
		$this->assign('ids',$_REQUEST['ids']);
		//所属中心筛选
		$this->assign('center_type',$this->get_oa_dep_list());
		//筛选判断
		$screen=$this->library_type_list($_REQUEST['classif']);
		foreach($screen as $key=>$value)
		{
			foreach($ids_array as $k=>$v)
			{
				foreach($value['second'] as $kk=>$vv)
				if($vv['id']==$v)
				{
					$screen[$key]['tid']=$v;
				}
			}
			if(empty($screen[$key]['tid'])){$screen[$key]['tid']=$value['second'][0]['id'];}
			$first_sort[]=$value['id'];
		}
		$this->assign('screen',$screen);
		$this->assign('screen_num',count($screen));
		$db_library_main=M('db_library_main');
		if($center_id!=-10 and $_REQUEST['type']==5){
			$where[]="find_in_set(".$_REQUEST['center_id'].",db_user.center_id)";
		}elseif($center_id!=-10 and $_REQUEST['type']!=5){
			$where[]="find_in_set(".$_REQUEST['center_id'].",db_library_main.center_id)";
		}
		$where['db_library_main.type']=$_REQUEST['type'];
		//排序
		$order_str="db_library_main.add_date desc";
		$ids_str=NULL;
		foreach($screen as $kk=>$vv)
		{
			$qb_id=NULL;
			foreach($vv['second'] as $kkk=>$vvv)
			{
				if($vvv['second_name']=='全部')
				{
					$qb_id=$vvv['id'];
				}
			}
			if($vv['tid']!=$qb_id){
				$ids_str.='db_library_main.id in (select main_id from db_universal_label_type where (find_in_set("'.$vv['tid'].'",sort_id))) and ';
			}
		}
		if(!empty($ids_str)){$where[]=rtrim($ids_str,'and ');}
		if($_REQUEST['type']==5){
			$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct,db_user.username,db_user.mobilephone,db_user.user_number')->where($where)->join('left join db_user on db_library_main.name=db_user.id')->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order('rank_id desc')->select();
		}else{
			$result=$db_library_main->field('db_library_main.*,pr.praisect,py.replyct')->where($where)->join(' LEFT JOIN (SELECT db_library_reading.mid,count(id) AS praisect FROM db_library_reading GROUP BY db_library_reading.mid) pr ON db_library_main.id = pr.mid')->join(' LEFT JOIN (SELECT db_library_reply.main_id,count(id) AS replyct FROM db_library_reply GROUP BY db_library_reply.main_id) py ON db_library_main.id = py.main_id')->group('db_library_main.id')->order($order_str)->select();
		}
		if($_REQUEST['type']==5){
			foreach($result as $key=>$value)
			{
				$result[$key]['name']=$value['username'];
			}
		}
		echo json_encode($result);die;
	}
	
	//公共方法-->标签管理-->操作 designed by:zhaoshihao 2016-11-09
	function label_administration_operation(){
		$db_universal_label1=M('db_universal_label1');
		$db_universal_label2=M('db_universal_label2');
		$db_universal_label_type=M('db_universal_label_type');
		$db_library_main=M('db_library_main');
		$db_user=M('db_user');
		if($_REQUEST['action']=='add'){
			//添加
			if($_REQUEST['labels']==1){
				$where['classif']=$_REQUEST['classif'];
				$where['parent_id']=!empty($_REQUEST['parent_id'])?$_REQUEST['parent_id']:NULL;
				$where['first_name']=$_REQUEST['first'];
				$where['fcenter_id']=$_REQUEST['fcenter_id'];
				$first=$db_universal_label1->where($where)->find();
				if(empty($first)){
					//添加一级分类
					$where_f['classif']=$_REQUEST['classif'];
					$where_f['fcenter_id']=$_REQUEST['fcenter_id'];
					$first_sort=$db_universal_label1->where($where_f)->max('first_sort');
					$where['first_sort']=$first_sort+1;
					$where['property']=$_REQUEST['property'];
					$where['add_uid']=$this->login_id;
					$where['add_date']=date('Y-m-d H:i:s');
					$fid=$db_universal_label1->add($where);
					//添加二级分类
					$where_s['first_id']=$fid;
					$where_s['second_sort']=1;
					$where_s['second_name']='全部';
					$where_s['add_uid']=$this->login_id;
					$where_s['add_date']=date('Y-m-d H:i:s');
					$db_universal_label2->add($where_s);
					$where_s['second_sort']=2;
					$where_s['second_name']=$_REQUEST['second'];
					$result_bool=$db_universal_label2->add($where_s);
					$where_s['second_sort']=3;
					$where_s['second_name']='其它';
					$id=$db_universal_label2->add($where_s);
					if($_REQUEST['classif']==1 or $_REQUEST['classif']==4 or $_REQUEST['classif']==9 or $_REQUEST['classif']==10 or $_REQUEST['classif']==11 or $_REQUEST['classif']==12 or $_REQUEST['classif']==14){
						//为之前的数据加个分类
						if($_REQUEST['classif']==1){
							$type_id=1;
						}elseif($_REQUEST['classif']==4){
							$type_id=2;
						}elseif($_REQUEST['classif']==9){
							$type_id=3;
						}elseif($_REQUEST['classif']==10){
							$type_id=4;
						}elseif($_REQUEST['classif']==11){
							$type_id=5;
						}elseif($_REQUEST['classif']==12){
							$type_id=6;
						}elseif($_REQUEST['classif']==14){
							$type_id=7;
						}
						if($type_id==7){
							$where_ma['type']=7;
							$main_id=$db_library_main->field('id')->where($where_ma)->select();
							$where_mad['sort_id']=$id;
							$where_mad['type_id']=$type_id;
							$where_mad['first_id']=$fid;
							foreach($main_id as $ka=>$va){
								$where_mad['main_id']=$va['id'];
								$db_universal_label_type->add($where_mad);
							}
						}else{
							if($type_id==3){
								$str="INSERT INTO db_universal_label_type (main_id,sort_id,type_id,first_id) SELECT main_id,'".$id."','".$type_id."','".$fid."' FROM db_universal_label_type inner join db_library_main on db_universal_label_type.main_id=db_library_main.id where (type_id='".$type_id."') AND (center_id='".$_REQUEST['fcenter_id']."') GROUP BY main_id";
							}else{
								$str="INSERT INTO db_universal_label_type (main_id,sort_id,type_id,first_id) SELECT main_id,'".$id."','".$type_id."','".$fid."' FROM db_universal_label_type where type_id='".$type_id."' GROUP BY main_id";
							}
							$Model=M();
							$Model->query($str);
						}
					}
				}else{
					$data['status']=self::NO;
					$data['msg']='该一级分类已存在';
					echo json_encode($data);die;
				}
			}elseif($_REQUEST['labels']==2){
				//添加二级分类
				$where_s['first_id']=$_REQUEST['first'];
				$where_s['second_name']=$_REQUEST['second'];
				$second=$db_universal_label2->where($where_s)->find();
				if(empty($second)){
					$second_sort=$db_universal_label2->where('first_id='.$_REQUEST['first'].'')->max('second_sort');
					$where_s['second_sort']=$second_sort+1;
					$where_s['add_uid']=$this->login_id;
					$where_s['add_date']=date('Y-m-d H:i:s');
					$result_bool=$db_universal_label2->add($where_s);
				}else{
					$data['status']=self::NO;
					$data['msg']='该二级分类已存在';
					echo json_encode($data);die;
				}
			}
		}elseif($_REQUEST['action']=='edit'){
			//编辑
			if($_REQUEST['labels']==1){
				//编辑一级分类
				$where['classif']=$_REQUEST['classif'];
				$where['first_name']=$_REQUEST['name'];
				$where['fcenter_id']=$_REQUEST['fcenter_id'];
				$first=$db_universal_label1->where($where)->find();
				if(empty($first)){
					$where['id']=$_REQUEST['id'];
					$result_bool=$db_universal_label1->save($where);
				}else{
					$data['status']=self::NO;
					if($_REQUEST['name']==$first['first_name']){
						$data['msg']='分类名未改动';
					}else{
						$data['msg']='该一级分类已存在';
					}
					echo json_encode($data);die;
				}
			}elseif($_REQUEST['labels']==2){
				//编辑二级分类
				$where['id']=$_REQUEST['id'];
				$name=$db_universal_label2->where($where)->find();
				$where_s['first_id']=$name['first_id'];
				$where_s['second_name']=$_REQUEST['name'];
				$second=$db_universal_label2->where($where_s)->find();
				if(empty($second)){
					$where['second_name']=$_REQUEST['name'];
					$result_bool=$db_universal_label2->save($where);
				}else{
					$data['status']=self::NO;
					if($_REQUEST['name']==$name['second_name']){
						$data['msg']='分类名未改动';
					}else{
						$data['msg']='该二级分类已存在';
					}
					echo json_encode($data);die;
				}
			}
		}elseif($_REQUEST['action']=='delete'){
			//删除
			if($_REQUEST['labels']==1){
				//删类别表包含该一级的分类
				$where_t['first_id']=$_REQUEST['id'];
				$second=$db_universal_label2->where($where_t)->select();
				foreach($second as $key=>$value){
					$where_main['_string']='find_in_set("'.$value['id'].'",sort_id)';
					$db_universal_label_type->where($where_main)->delete();
				}
				//删二级分类
				$where_s['first_id']=$_REQUEST['id'];
				$db_universal_label2->where($where_s)->delete();
				$where_f['id']=$_REQUEST['id'];
				//删一级分类
				$result_bool=$db_universal_label1->where($where_f)->delete();
				//一级分类重新排序
				$where_d['classif']=$_REQUEST['classif'];
				$where_d['fcenter_id']=$_REQUEST['fcenter_id'];
				$arr=$db_universal_label1->where($where_d)->order('first_sort')->select();
				foreach($arr as $key=>$value){
					$where_nt['id']=$value['id'];
					$where_nt['first_sort']=$key+1;
					$db_universal_label1->save($where_nt);
				}
			}elseif($_REQUEST['labels']==2){
				$where_s['id']=$_REQUEST['id'];
				$desecond=$db_universal_label2->where($where_s)->find();
				if($_REQUEST['bool']!=1){
					//删类别表包含该二级的分类
					if(($_REQUEST['classif']==1) || ($_REQUEST['classif']==4) || ($_REQUEST['classif']==9) || ($_REQUEST['classif']==10) || ($_REQUEST['classif']==11) || ($_REQUEST['classif']==12) || ($_REQUEST['classif']==14)){
						$where_a['_string']='find_in_set("'.$_REQUEST['id'].'",sort_id)';
						$second=$db_universal_label_type->where($where_a)->select();
						foreach($second as $key=>$value){
							$arr=explode(',',$value['sort_id']);
							foreach($arr as $kk=>$vv){
								if($vv==$_REQUEST['id']){
									$arr[$kk]=$_REQUEST['cid'];
								}
							}
							$result=array_unique($arr);
							sort($result);
							$where_o['sort_id']=join(",",$result);
							$where_o['id']=$value['id'];
							$db_universal_label_type->save($where_o);
						}
					}elseif($_REQUEST['classif']==6){
						$db_project_bg=M('db_project_bg');
						$db_project_uploads=M('db_project_uploads');
						if($desecond['first_id']==22){
							$where_a['_string']='find_in_set("'.$_REQUEST['id'].'",p_type)';
							$second=$db_project_bg->where($where_a)->select();
							foreach($second as $key=>$value){
								$arr=explode(',',$value['p_type']);
								foreach($arr as $kk=>$vv){
									if($vv==$_REQUEST['id']){
										$arr[$kk]=$_REQUEST['cid'];
									}
								}
								$result=array_unique($arr);
								sort($result);
								$where_o['p_type']=join(",",$result);
								$where_o['id']=$value['id'];
								$db_project_bg->save($where_o);
							}
						}elseif($desecond['first_id']==23){
							$where_a['_string']='find_in_set("'.$_REQUEST['id'].'",business_type)';
							$second=$db_project_bg->where($where_a)->select();
							foreach($second as $key=>$value){
								$arr=explode(',',$value['business_type']);
								foreach($arr as $kk=>$vv){
									if($vv==$_REQUEST['id']){
										$arr[$kk]=$_REQUEST['cid'];
									}
								}
								$result=array_unique($arr);
								sort($result);
								$where_o['business_type']=join(",",$result);
								$where_o['id']=$value['id'];
								$db_project_bg->save($where_o);
							}
						}elseif($desecond['first_id']==24){
							$where_a['_string']='find_in_set("'.$_REQUEST['id'].'",type)';
							$second=$db_project_uploads->where($where_a)->select();
							foreach($second as $key=>$value){
								$arr=explode(',',$value['type']);
								foreach($arr as $kk=>$vv){
									if($vv==$_REQUEST['id']){
										$arr[$kk]=$_REQUEST['cid'];
									}
								}
								$result=array_unique($arr);
								sort($result);
								$where_o['type']=join(",",$result);
								$where_o['id']=$value['id'];
								$db_project_uploads->save($where_o);
							}
						}
					}elseif($_REQUEST['classif']==5){
						$db_user=M('db_user');
						if($desecond['first_id']==8){
							$where_a['_string']='find_in_set("'.$_REQUEST['id'].'",position_id)';
							$second=$db_user->where($where_a)->select();
							foreach($second as $key=>$value){
								$arr=explode(',',$value['position_id']);
								foreach($arr as $kk=>$vv){
									if($vv==$_REQUEST['id']){
										$arr[$kk]=$_REQUEST['cid'];
									}
								}
								$result=array_unique($arr);
								sort($result);
								$where_o['position_id']=join(",",$result);
								$where_o['id']=$value['id'];
								$db_user->save($where_o);
							}
						}else{
							$where_a['_string']='find_in_set("'.$_REQUEST['id'].'",department_id)';
							$second=$db_user->where($where_a)->select();
							foreach($second as $key=>$value){
								$arr=explode(',',$value['department_id']);
								foreach($arr as $kk=>$vv){
									if($vv==$_REQUEST['id']){
										$arr[$kk]=$_REQUEST['cid'];
									}
								}
								$result=array_unique($arr);
								sort($result);
								$where_o['department_id']=join(",",$result);
								$where_o['id']=$value['id'];
								$db_user->save($where_o);
							}
						}
					}
				}
				//删二级分类
				$result_bool=$db_universal_label2->where($where_s)->delete();
				//二级分类重新排序
				$where_sort['first_id']=$desecond['first_id'];
				$arr=$db_universal_label2->where($where_sort)->order('second_sort')->select();
				foreach($arr as $key=>$value){
					$where_nt['id']=$value['id'];
					$where_nt['second_sort']=$key+1;
					$db_universal_label2->save($where_nt);
				}
			}
		}elseif($_REQUEST['action']=='sort'){
			//排序
			if($_REQUEST['labels']==1){
				foreach($_REQUEST['mid_array'] as $key=>$value){
					$where['id']=$value;
					$where['first_sort']=$key+1;
					$db_universal_label1->save($where);
					$result_bool=1;
				}
			}elseif($_REQUEST['labels']==2){
				foreach($_REQUEST['mid_array'] as $key=>$value){
					$where['id']=$value;
					$where['second_sort']=$key+2;
					$db_universal_label2->save($where);
					$result_bool=1;
				}
			}
		}elseif($_REQUEST['action']=='data'){
			$main_id=implode(',',$_REQUEST['main_id']);
			$first_id=$_REQUEST['first_id'];
			$type_id=$_REQUEST['type_id'];
			$second_id=$_REQUEST['second_id'];
			//判断单选复选
			$where_l['id']=$first_id;
			$label1=$db_universal_label1->where($where_l)->find();
			if($label1['property']==1){
				$where_t['main_id']=array('in',$main_id);
				$where_t['first_id']=$first_id;
				$where_s['sort_id']=$second_id;
				$result_bool=$db_universal_label_type->where($where_t)->save($where_s);
			}else{
				$where_t['main_id']=array('in',$main_id);
				$where_t['first_id']=$first_id;
				$label_type=$db_universal_label_type->where($where_t)->select();
				foreach($label_type as $key=>$value){
					$sort_id=implode(',',array_unique(explode(',',$value['sort_id'].','.$second_id)));
					$where_s['sort_id']=$sort_id;
					$result_bool=$db_universal_label_type->where($where_t)->save($where_s);
				}
			}
		}
		if($result_bool)
		{
			$data['status']=self::YES;
		}
		else
		{
			$data['status']=self::NO;
		}
		echo json_encode($data);die;
	}

	//公共方法-->功能页面添加标签 designed by:zhaoshihao 2017-11-09
	function label_add_ajax(){
		$db_universal_label2=M('db_universal_label2');
		$where['first_id']=$_REQUEST['first_id'];
		$where['second_name']=$_REQUEST['type_name'];
		$bool_same=$db_universal_label2->where($where)->find();
		if(!empty($bool_same))
		{
			$data['status']=self::NO;
			echo json_encode($data);die;
		}
		unset($where['second_name']);
		$sort=$db_universal_label2->where($where)->max('second_sort');
		$where['second_name']=$_REQUEST['type_name'];
		$where['second_sort']=$sort+1;
		$where['add_uid']=$this->login_id;
		$where['add_date']=date('Y-m-d H:i:s');
		$data['id']=$db_universal_label2->add($where);
		$data['name']=$_REQUEST['type_name'];
		echo json_encode($data);die;
	}
	
	//设置操作 designed by:zhaoshihao 2017-11-09
	function sz_audit(){
		$db_universal_type=M('db_universal_type');
		$db_library_share=M('db_library_share');
		$db_library_share_starus=M('db_library_share_starus');
		if($_REQUEST['action']=='zd_submit'){
			$where['type']=10;
			$where['name1']=$_REQUEST['type'];
			$where_s['name2']=1;
			$result_bool=$db_universal_type->where($where)->save($where_s);
		}elseif($_REQUEST['action']=='zd_resubmit'){
			$where['type']=10;
			$where['name1']=$_REQUEST['type'];
			$where_s['name2']=-1;
			$result_bool=$db_universal_type->where($where)->save($where_s);
		}elseif($_REQUEST['action']=='fx_submit'){
			$where['type']=10;
			$where['name1']=$_REQUEST['type'];
			$where_s['name3']=1;
			$result_bool=$db_universal_type->where($where)->save($where_s);
		}elseif($_REQUEST['action']=='fx_resubmit'){
			$where['type']=10;
			$where['name1']=$_REQUEST['type'];
			$where_s['name3']=-1;
			$result_bool=$db_universal_type->where($where)->save($where_s);
		}elseif($_REQUEST['action']=='tj_submit'){
			$where['type']=10;
			$where['name1']=$_REQUEST['type'];
			$where_s['name4']=1;
			$result_bool=$db_universal_type->where($where)->save($where_s);
		}elseif($_REQUEST['action']=='tj_resubmit'){
			$where['type']=10;
			$where['name1']=$_REQUEST['type'];
			$where_s['name4']=-1;
			$result_bool=$db_universal_type->where($where)->save($where_s);
		}elseif($_REQUEST['action']=='fx_add'){
			if(empty($_REQUEST['mid'])){
				//文件夹添加
				$where['folder_name']=$_REQUEST['folder_txt'];
				$where['folder_type']=$_REQUEST['folder_type'];
				$where['mid']=join(',',$_REQUEST['main_id']);
				$where['add_uid']=$this->login_id;
				$where['add_date']=date('Y-m-d H:i:s');
				$result_bool=$db_library_share->add($where);
			}else{
				//文件夹编辑
				$where['id']=$_REQUEST['mid'];
				$where['folder_name']=$_REQUEST['folder_txt'];
				$where['mid']=join(',',$_REQUEST['main_id']);
				$result_bool=$db_library_share->save($where);
			}
		}elseif($_REQUEST['action']=='fx_delete'){
			//文件夹删除
			$where['id']=$_REQUEST['id'];
			$result_bool=$db_library_share->where($where)->delete();
			$where_d['sid']=$_REQUEST['id'];
			$db_library_share_starus->where($where_d)->delete();
		}elseif($_REQUEST['action']=='fx_top'){
			//文件夹分享
			$where['id']=$_REQUEST['id'];
			$share=$db_library_share->where($where)->find();
			if(empty($share['share_uids'])){
				$where['share_uids']=$_REQUEST['share_uids'];
				$where['share_date']=date('Y-m-d H:i:s');
				$result_bool=$db_library_share->save($where);
				foreach(explode(',',$share['mid']) as $key=>$val){
					foreach(explode(',',$_REQUEST['share_uids']) as $kk=>$vv){
						$where_d['sid']=$_REQUEST['id'];
						$where_d['mid']=$val;
						$where_d['suid']=$vv;
						$where_d['rstatus']=-1;
						$db_library_share_starus->add($where_d);
					}
				}
			}else{
				$aa=explode(',',$_REQUEST['share_uids']);
				$bb=explode(',',$share['share_uids']);
				sort($aa);
				sort($bb);
				$re=join(',',$aa);
				$ha=join(',',$bb);
				if($re==$ha){
					$result_bool=1;
				}else{
					//主表
					$where['share_uids']=$re;
					$result_bool=$db_library_share->save($where);
					//副表
					foreach($aa as $ka=>$va){
						foreach($bb as $kb=>$vb){
							if($va==$vb){
								$yy[]=$va;
								unset($aa[$ka]);
								unset($bb[$kb]);
							}
						}
					}
					foreach(explode(',',$share['mid']) as $key=>$val){
						foreach($aa as $kaa=>$vaa){
							$where_a['sid']=$_REQUEST['id'];
							$where_a['mid']=$val;
							$where_a['suid']=$vaa;
							$where_a['rstatus']=-1;
							$db_library_share_starus->add($where_a);
						}
					}
					foreach($bb as $kbb=>$vbb){
						$where_b['sid']=$_REQUEST['id'];
						$where_b['suid']=$vbb;
						$db_library_share_starus->where($where_b)->delete();
					}
				}
			}
		}elseif($_REQUEST['action']=='fx_down'){
			//文件夹取消分享
			$where['id']=$_REQUEST['id'];
			$where['share_uids']=NULL;
			$where['share_date']=NULL;
			$result_bool=$db_library_share->save($where);
			$where_d['sid']=$_REQUEST['id'];
			$db_library_share_starus->where($where_d)->delete();
		}
		if($result_bool)
		{
			$data['status']=self::YES;
		}
		else
		{
			$data['status']=self::NO;
		}
		echo json_encode($data);die;
	}
	
	//评分 designed by:zhaoshihao 2018-01-03
	function jixiao_appraisal(){
		$id=$this->login_id;
		$db_jixiao_join=M('db_jixiao_join');
		$where_one['_string']="FIND_IN_SET('$id',sup_uid1) or FIND_IN_SET('$id',sup_uid2)";
		$where_one['year_type']='20172';
		$result=$db_jixiao_join->where($where_one)->group('id desc')->select();
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		foreach($result as $key=>$value){
			if(in_array($this->login_id,explode(',',$value['sup_uid1']))){
				$result[$key]['sup1']=1;
				$where_s['mid']=$value['id'];
				$where_s['standard']=$value['standard1'];
				$where_s['year_type']='20172';
				$where_s['add_uid']=$id;
				$sup1=$db_jixiao_appraisal->where($where_s)->find();
				$result[$key]['sup1_id']=$sup1['id'];
				$result[$key]['sup1_sum']=$sup1['sum_all'];
				$result[$key]['able1']=$sup1['able'];
				$result[$key]['sup1_status']=$sup1['status'];
			}
			if(in_array($this->login_id,explode(',',$value['sup_uid2']))){
				$result[$key]['sup2']=1;
				$where_s2['mid']=$value['id'];
				$where_s2['standard']=$value['standard2'];
				$where_s2['year_type']='20172';
				$where_s2['add_uid']=$id;
				$sup2=$db_jixiao_appraisal->where($where_s2)->find();
				$result[$key]['sup2_id']=$sup2['id'];
				$result[$key]['sup2_sum']=$sup2['sum_all'];
				$result[$key]['able2']=$sup2['able'];
				$result[$key]['sup2_status']=$sup2['status'];
			}
			if(in_array($this->login_id,explode(',',$value['sup_uid3']))){
				$result[$key]['sup3']=1;
				$result[$key]['sup3_sum']=$value['sup_uid3_sum'];
			}
		}
		$result=$this->multi_array_sort($result,'sup1',SORT_DESC);
		$this->assign("result",$result);
		$this->display();
	}
	
	//评分-->操作  designed by:zhaoshihao 2018-01-03
	function jixiao_appraisal_ajax(){
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_join=M('db_jixiao_join');
		$where_a['id']=$_REQUEST['id'];
		$sup1=$db_jixiao_join->where($where_a)->find();
		$where_s['mid']=$_REQUEST['id'];
		if($_REQUEST['action']=='able' or $_REQUEST['action']=='disable'){
			$where_s['standard']=$sup1['standard1'];
		}else{
			$where_s['standard']=$sup1['standard2'];
		}
		$where_s['year_type']='20172';
		$where_s['add_uid']=$this->login_id;
		$app1=$db_jixiao_appraisal->where($where_s)->find();
		if($_REQUEST['action']=='able' or $_REQUEST['action']=='able2'){
			$where['id']=$app1['id'];
			$where['able']=1;
			$db_jixiao_appraisal->save($where);
		}elseif($_REQUEST['action']=='disable' or $_REQUEST['action']=='disable2'){
			if(empty($app1)){
				$where['mid']=$_REQUEST['id'];
				$where['uid']=$sup1['uid'];
				$where['username']=$this->get_username($sup1['uid']);
				$where['department']=$sup1['department'];
				$where['position']=$sup1['position'];
				$where['status']=-1;
				$where['type']=$sup1['appraisal_type'];
				if($_REQUEST['action']=='disable'){
					$where['standard']=$sup1['standard1'];
				}else{
					$where['standard']=$sup1['standard2'];
				}
				$where['able']=-1;
				$where['year_type']=20172;
				$where['add_uid']=$this->login_id;
				$where['add_date']=date("Y-m-d H:i:s");
				$db_jixiao_appraisal->add($where);
			}else{
				$where['id']=$app1['id'];
				$where['able']=-1;
				$db_jixiao_appraisal->save($where);
			}
		}
		$data['status']=self::YES;
		echo json_encode($data);die;
	}
	
	//绩效评分 designed by:zhaoshihao 2018-01-03
	function jixiao_evaluation_one(){
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_join=M('db_jixiao_join');
		$db_jixiao_form=M('db_jixiao_form');
		//对应评价表
		$where_a['id']=$_REQUEST['id'];
		$sup1=$db_jixiao_join->where($where_a)->find();
		$sup1['position_name']=$this->get_db_universal_label(2,$sup1['position']);
		$sup1['department_name']=$this->get_db_universal_label(2,$sup1['department']);
		$this->assign("sup1",$sup1);
		//评价表数据
		$where_f['tid']=$sup1['standard1'];
		$where_f['year_type']='20172';
		$tid=$db_jixiao_form->where($where_f)->find();
		$this->assign("tid",$tid);
		//判断有无评价
		$where_s['mid']=$_REQUEST['id'];
		$where_s['standard']=$sup1['standard1'];
		$where_s['year_type']='20172';
		$where_s['add_uid']=$this->login_id;
		$app1=$db_jixiao_appraisal->where($where_s)->find();
		if(!empty($app1) and !empty($app1['sum_all']) and ($app1['status']==1)){
			$app1['jg']=$app1['jg']?$app1['jg']:0;
			$app1['xg1']=$app1['xg1']?$app1['xg1']:0;
			$app1['dg1']=$app1['dg1']?$app1['dg1']:0;
			$app1['by']=$app1['by']?$app1['by']:0;
			$app1['xg2']=$app1['xg2']?$app1['xg2']:0;
			$app1['dg2']=$app1['dg2']?$app1['dg2']:0;
			$app1['sum_pj1']=($app1['sum1']+$app1['sum2']+$app1['sum3']+$app1['sum4'])/4;
			$app1['sum_pj2']=($app1['sum5']+$app1['sum6']+$app1['sum7']+$app1['sum8']+$app1['sum9']+$app1['sum10']+$app1['sum11']+$app1['sum12'])/8;
			if(empty($app1['sum17'])){
				$app1['sum_pj3']=($app1['sum13']+$app1['sum14']+$app1['sum15']+$app1['sum16'])/4;
			}else{
				$app1['sum_pj3']=($app1['sum13']+$app1['sum14']+$app1['sum15']+$app1['sum16']+$app1['sum17'])/5;
			}
		}
		$this->assign("app1",$app1);
		$this->assign("id",$_REQUEST['id']);
		$_SESSION['jixiao_appraisal']=__APP__."/Index/jixiao_appraisal";
		$this->display();
	}
	
	//绩效评分-->添加编辑 designed by:zhaoshihao 2018-01-03
	function jixiao_evaluation_one_ajax(){
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_join=M('db_jixiao_join');
		$db_jixiao_form=M('db_jixiao_form');
		//对应评价表
		$where_a['id']=$_REQUEST['id'];
		$sup1=$db_jixiao_join->where($where_a)->find();
		//判断有无评价
		$where_s['mid']=$_REQUEST['id'];
		$where_s['standard']=$sup1['standard1'];
		$where_s['year_type']='20172';
		$where_s['add_uid']=$this->login_id;
		$app1=$db_jixiao_appraisal->where($where_s)->find();
		if($_REQUEST['action']=='add'){
			$where['mid']=$_REQUEST['id'];
			$where['uid']=$sup1['uid'];
			$where['username']=$this->get_username($sup1['uid']);
			$where['department']=$sup1['department'];
			$where['position']=$sup1['position'];
			$where['status']=1;
			$where['able']=1;
			$where['type']=$sup1['appraisal_type'];
			$where['standard']=$sup1['standard1'];
			$s1=0;$s2=0;$s3=0;
			foreach($_REQUEST['sum'] as $key=>$val){
				if($key+1<=4){
					$pj1+=$val;
					$s1++;
				}
				if($key+1<=12 and $key+1>4){
					$pj2+=$val;
					$s2++;
				}
				if($key+1>12){
					$pj3+=$val;
					$s3++;
				}
				$sum='sum'.($key+1);
				$where[$sum]=$val;
			}
			$pj1=$pj1/$s1*4;
			$pj2=$pj2/$s2*3;
			$pj3=$pj3/$s3*3;
			$where['sumI']=$pj1+$pj2+$pj3;
			if(!empty($_REQUEST['jg'])){$where['jg']=$_REQUEST['jg'];}
			if(!empty($_REQUEST['xg1'])){$where['xg1']=$_REQUEST['xg1'];}
			if(!empty($_REQUEST['dg1'])){$where['dg1']=$_REQUEST['dg1'];}
			$where['sumII']=$_REQUEST['jg']+$_REQUEST['xg1']*3+$_REQUEST['dg1']*9;
			if(!empty($_REQUEST['by'])){$where['by']=$_REQUEST['by'];}
			if(!empty($_REQUEST['xg2'])){$where['xg2']=$_REQUEST['xg2'];}
			if(!empty($_REQUEST['dg2'])){$where['dg2']=$_REQUEST['dg2'];}
			$where['sumIII']=$_REQUEST['by']+$_REQUEST['xg2']*3+$_REQUEST['dg2']*9;
			$where['sum_all']=($pj1+$pj2+$pj3)-($_REQUEST['jg']+$_REQUEST['xg1']*3+$_REQUEST['dg1']*9)+($_REQUEST['by']+$_REQUEST['xg2']*3+$_REQUEST['dg2']*9);
			$where['comment']=$_REQUEST['comment'];
			$where['year_type']=20172;
			$where['add_uid']=$this->login_id;
			$where['add_date']=date("Y-m-d H:i:s");
			$db_jixiao_appraisal->add($where);
		}elseif($_REQUEST['action']=='edit'){
			$where['id']=$app1['id'];
			$where['status']=1;
			$where['able']=1;
			$s1=0;$s2=0;$s3=0;
			foreach($_REQUEST['sum'] as $key=>$val){
				if($key+1<=4){
					$pj1+=$val;
					$s1++;
				}
				if($key+1<=12 and $key+1>4){
					$pj2+=$val;
					$s2++;
				}
				if($key+1>12){
					$pj3+=$val;
					$s3++;
				}
				$sum='sum'.($key+1);
				$where[$sum]=$val;
			}
			$pj1=$pj1/$s1*4;
			$pj2=$pj2/$s2*3;
			$pj3=$pj3/$s3*3;
			$where['sumI']=$pj1+$pj2+$pj3;
			if(!empty($_REQUEST['jg'])){$where['jg']=$_REQUEST['jg'];}else{$where['jg']=NULL;}
			if(!empty($_REQUEST['xg1'])){$where['xg1']=$_REQUEST['xg1'];}else{$where['xg1']=NULL;}
			if(!empty($_REQUEST['dg1'])){$where['dg1']=$_REQUEST['dg1'];}else{$where['dg1']=NULL;}
			$where['sumII']=$_REQUEST['jg']+$_REQUEST['xg1']*3+$_REQUEST['dg1']*9;
			if(!empty($_REQUEST['by'])){$where['by']=$_REQUEST['by'];}else{$where['by']=NULL;}
			if(!empty($_REQUEST['xg2'])){$where['xg2']=$_REQUEST['xg2'];}else{$where['xg2']=NULL;}
			if(!empty($_REQUEST['dg2'])){$where['dg2']=$_REQUEST['dg2'];}else{$where['dg2']=NULL;}
			$where['sumIII']=$_REQUEST['by']+$_REQUEST['xg2']*3+$_REQUEST['dg2']*9;
			$where['sum_all']=($pj1+$pj2+$pj3)-($_REQUEST['jg']+$_REQUEST['xg1']*3+$_REQUEST['dg1']*9)+($_REQUEST['by']+$_REQUEST['xg2']*3+$_REQUEST['dg2']*9);
			$where['comment']=$_REQUEST['comment'];
			$db_jixiao_appraisal->save($where);
		}elseif($_REQUEST['action']=='down'){
			$where['id']=$app1['id'];
			$where['status']=-1;
			$db_jixiao_appraisal->save($where);
		}
		$data['status']=self::YES;
		$data['id']=$_REQUEST['id'];
		echo json_encode($data);die;
	}
	
	//360评分 designed by:zhaoshihao 2018-01-03
	function jixiao_evaluation_two(){
		$db_jixiao_join=M('db_jixiao_join');
		$db_jixiao_form=M('db_jixiao_form');
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		//对应评价表
		$where_a['id']=$_REQUEST['id'];
		$sup1=$db_jixiao_join->where($where_a)->find();
		$sup1['position_name']=$this->get_db_universal_label(2,$sup1['position']);
		$sup1['department_name']=$this->get_db_universal_label(2,$sup1['department']);
		$this->assign("sup1",$sup1);
		//评价表数据
		$where_f['tid']=$sup1['standard2'];
		$where_f['year_type']='20172';
		$tid=$db_jixiao_form->where($where_f)->find();
		$this->assign("tid",$tid);
		//判断有无评价
		$where_s['mid']=$_REQUEST['id'];
		$where_s['standard']=$sup1['standard2'];
		$where_s['year_type']='20172';
		$where_s['add_uid']=$this->login_id;
		$app1=$db_jixiao_appraisal->where($where_s)->find();
		$this->assign("app1",$app1);
		$this->assign("id",$_REQUEST['id']);
		$_SESSION['jixiao_appraisal']=__APP__."/Index/jixiao_appraisal";
		$this->display();
	}
	
	//360评分-->添加编辑 designed by:zhaoshihao 2018-01-03
	function jixiao_evaluation_two_ajax(){
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_join=M('db_jixiao_join');
		$db_jixiao_form=M('db_jixiao_form');
		//对应评价表
		$where_a['id']=$_REQUEST['id'];
		$sup1=$db_jixiao_join->where($where_a)->find();
		//判断有无评价
		$where_s['mid']=$_REQUEST['id'];
		$where_s['standard']=$sup1['standard2'];
		$where_s['year_type']='20172';
		$where_s['add_uid']=$this->login_id;
		$app1=$db_jixiao_appraisal->where($where_s)->find();
		if($_REQUEST['action']=='add'){
			$where['mid']=$_REQUEST['id'];
			$where['uid']=$sup1['uid'];
			$where['username']=$this->get_username($sup1['uid']);
			$where['department']=$sup1['department'];
			$where['position']=$sup1['position'];
			$where['status']=1;
			$where['able']=1;
			$where['type']=$sup1['appraisal_type'];
			$where['standard']=$sup1['standard2'];
			$s1=0;$s2=0;$s3=0;
			foreach($_REQUEST['sum'] as $key=>$val){
				if($key+1<=4){
					$pj1+=$val;
					$s1++;
				}
				if($key+1<=12 and $key+1>4){
					$pj2+=$val;
					$s2++;
				}
				if($key>12){
					$pj3+=$val;
					$s3++;
				}
				$sum='sum'.($key+1);
				$where[$sum]=$val;
				$sum_mess='sum_mess'.($key+1);
				$where[$sum_mess]=$_REQUEST['sum_mess'][$key];
				$where['sum_all']+=$val;
			}
			$where['comment']=$_REQUEST['comment'];
			$where['year_type']=20172;
			$where['add_uid']=$this->login_id;
			$where['add_date']=date("Y-m-d H:i:s");
			$db_jixiao_appraisal->add($where);
		}elseif($_REQUEST['action']=='edit'){
			$where['id']=$app1['id'];
			$where['status']=1;
			$where['able']=1;
			$s1=0;$s2=0;$s3=0;
			foreach($_REQUEST['sum'] as $key=>$val){
				if($key+1<=4){
					$pj1+=$val;
					$s1++;
				}
				if($key+1<=12 and $key+1>4){
					$pj2+=$val;
					$s2++;
				}
				if($key>12){
					$pj3+=$val;
					$s3++;
				}
				$sum='sum'.($key+1);
				$where[$sum]=$val;
				$sum_mess='sum_mess'.($key+1);
				$where[$sum_mess]=$_REQUEST['sum_mess'][$key];
				$where['sum_all']+=$val;
			}
			$where['comment']=$_REQUEST['comment'];
			$db_jixiao_appraisal->save($where);
		}elseif($_REQUEST['action']=='down'){
			$where['id']=$app1['id'];
			$where['status']=-1;
			$db_jixiao_appraisal->save($where);
		}
		$data['status']=self::YES;
		$data['id']=$_REQUEST['id'];
		echo json_encode($data);die;
	}
	
	//个人绩效 designed by:zhaoshihao 2018-01-03
	function jixiao_personal(){
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_form=M('db_jixiao_form');
		$db_jixiao_join=M('db_jixiao_join');
		$where['uid']=$this->login_id;
		$where['year_type']=20172;
		$join=$db_jixiao_join->where($where)->find();
		foreach(explode(",",$join['zhanbi']) as $kk=>$vv){
			$bl[($kk+1)]=$vv;
		}
		$this->assign("bl",$bl);
		//领导考评
		$where_1['uid']=$this->login_id;
		$where_1['status']=1;
		$where_1['able']=1;
		$where_1['standard']=$join['standard1'];
		$where_1['year_type']=20172;
		$result['sum1']=$db_jixiao_appraisal->where($where_1)->Avg('sum_all')+0;
		$sum1_p=explode(",",$join['sup_uid1']);
		$s1_yp=$db_jixiao_appraisal->field('add_uid')->where($where_1)->select();
		$sum1_y=array();
		foreach($s1_yp as $k1=>$v1){
			$sum1_y[]=$v1['add_uid'];
		}
		foreach($sum1_p as $kk=>$vv){
			foreach($sum1_y as $kkk=>$vvv){
				if($vv==$vvv){
					$yp1[]=$vv;
					unset($sum1_p[$kk]);
				}
			}
		}
		foreach($yp1 as $a1=>$b1){
			$where_y1['uid']=$this->login_id;
			$where_y1['status']=1;
			$where_y1['able']=1;
			$where_y1['standard']=$join['standard1'];
			$where_y1['year_type']=20172;
			$where_y1['add_uid']=$b1;
			$yp1s=$db_jixiao_appraisal->where($where_y1)->find();
			$yp11[]=$this->get_username($b1).':'.$yp1s['sum_all'];
		}
		foreach($sum1_p as $c1=>$d1){
			$wp1[]=$this->get_username($d1);
		}
		$result['sum1_yp']=join(',',$yp11);
		$result['sum1_wp']=join(',',$wp1);
		//360考评
		$where_2['uid']=$this->login_id;
		$where_2['status']=1;
		$where_2['able']=1;
		$where_2['standard']=$join['standard2'];
		$where_2['year_type']=20172;
		$result['sum2']=round($db_jixiao_appraisal->where($where_2)->Avg('sum_all')+0,2);
		$sum2_p=explode(",",$join['sup_uid2']);
		$s2_yp=$db_jixiao_appraisal->field('add_uid')->where($where_2)->select();
		$sum2_y=array();
		foreach($s2_yp as $k2=>$v2){
			$sum2_y[]=$v2['add_uid'];
		}
		foreach($sum2_p as $kk2=>$vv2){
			foreach($sum2_y as $kkk2=>$vvv2){
				if($vv2==$vvv2){
					$yp2[]=$vv2;
					unset($sum2_p[$kk2]);
				}
			}
		}
		foreach($yp2 as $a2=>$b2){
			$where_y2['uid']=$this->login_id;
			$where_y2['status']=1;
			$where_y2['able']=1;
			$where_y2['standard']=$join['standard2'];
			$where_y2['year_type']=20172;
			$where_y2['add_uid']=$b2;
			$yp2s=$db_jixiao_appraisal->where($where_y2)->find();
			$yp22[]=$this->get_username($b2).':'.$yp2s['sum_all'];
		}
		foreach($sum2_p as $c2=>$d2){
			$wp2[]=$this->get_username($d2);
		}
		$result['sum2_yp']=join(',',$yp22);
		$result['sum2_wp']=join(',',$wp2);
		//PBC
		$result['sum3']=$join['sup_uid3_sum']+0;
		//述职
		$result['sum4']=$join['sup_uid4_sum']+0;
		$result['sum']=round(($result['sum1']*$bl[1]+$result['sum2']*$bl[2]+$result['sum3']*$bl[3]+$result['sum4']*$bl[4])*0.01,2);
		$result['standard1']=$join['standard1'];
		$result['standard1']=$join['standard1'];
		$result['id']=$join['id'];
		$this->assign("result",$result);
		$this->assign("join",$join);
		$this->display();
	}
	
	//考评人详情 designed by:zhaoshihao 2018-01-03
	function jixiao_person(){
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_form=M('db_jixiao_form');
		$db_jixiao_join=M('db_jixiao_join');
		$where['id']=$_REQUEST['id'];
		$join=$db_jixiao_join->where($where)->find();
		if($_REQUEST['standard']=='standard1'){
			//领导考评
			$prople=explode(",",$join['sup_uid1']);
			foreach($prople as $key=>$val){
				$where_s['mid']=$_REQUEST['id'];
				$where_s['status']=1;
				$where_s['able']=1;
				$where_s['add_uid']=$val;
				$where_s['standard']=$join['standard1'];
				$where_s['year_type']=20172;
				$detail=$db_jixiao_appraisal->where($where_s)->find();
				$result[$key]['add_user']=$this->get_username($val);
				$result[$key]['sum']=$detail['sum_all'];
				$result[$key]['id']=$detail['id'];
				$result[$key]['able']=$detail['able'];
				$result[$key]['status']=$detail['status'];
			}
			$this->assign("sta",1);
		}else{
			//360考评
			$prople=explode(",",$join['sup_uid2']);
			foreach($prople as $key=>$val){
				$where_s['mid']=$_REQUEST['id'];
				$where_s['status']=1;
				$where_s['able']=1;
				$where_s['add_uid']=$val;
				$where_s['standard']=$join['standard2'];
				$where_s['year_type']=20172;
				$detail=$db_jixiao_appraisal->where($where_s)->find();
				$result[$key]['add_user']=$this->get_username($val);
				$result[$key]['sum']=$detail['sum_all'];
				$result[$key]['id']=$detail['id'];
				$result[$key]['able']=$detail['able'];
				$result[$key]['status']=$detail['status'];
			}
			$this->assign("sta",2);
		}
		$result=$this->multi_array_sort($result,'sum',SORT_DESC);
		$this->assign("result",$result);
		$this->display();
	}
	
	//详情 designed by:zhaoshihao 2018-01-03
	function jixiao_detail(){
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_form=M('db_jixiao_form');
		$db_jixiao_join=M('db_jixiao_join');
		//评分表
		$where_s['id']=$_REQUEST['id'];
		$app1=$db_jixiao_appraisal->where($where_s)->find();
		$app1['jg']=$app1['jg']?$app1['jg']:0;
		$app1['xg1']=$app1['xg1']?$app1['xg1']:0;
		$app1['dg1']=$app1['dg1']?$app1['dg1']:0;
		$app1['by']=$app1['by']?$app1['by']:0;
		$app1['xg2']=$app1['xg2']?$app1['xg2']:0;
		$app1['dg2']=$app1['dg2']?$app1['dg2']:0;
		$app1['sum_pj1']=($app1['sum1']+$app1['sum2']+$app1['sum3']+$app1['sum4'])/4;
		$app1['sum_pj2']=($app1['sum5']+$app1['sum6']+$app1['sum7']+$app1['sum8']+$app1['sum9']+$app1['sum10']+$app1['sum11']+$app1['sum12'])/8;
		if(empty($app1['sum17'])){
			$app1['sum_pj3']=($app1['sum13']+$app1['sum14']+$app1['sum15']+$app1['sum16'])/4;
		}else{
			$app1['sum_pj3']=($app1['sum13']+$app1['sum14']+$app1['sum15']+$app1['sum16']+$app1['sum17'])/5;
		}
		$app1['add_user']=$this->get_username($app1['add_uid']);
		$this->assign("app1",$app1);
		//对应评价表
		$where_a['uid']=$app1['uid'];
		$where_a['year_type']='20172';
		$sup1=$db_jixiao_join->where($where_a)->find();
		$sup1['position_name']=$this->get_db_universal_label(2,$sup1['position']);
		$sup1['department_name']=$this->get_db_universal_label(2,$sup1['department']);
		$this->assign("sup1",$sup1);
		//评价表数据
		if($_REQUEST['sta']=='1'){$where_f['tid']=$sup1['standard1'];}else{$where_f['tid']=$sup1['standard2'];}
		$where_f['year_type']='20172';
		$tid=$db_jixiao_form->where($where_f)->find();
		$this->assign("tid",$tid);
		if($_REQUEST['sta']=='1'){
			$this->display('jixiao_detail_one');
		}else{
			$this->display('jixiao_detail_two');
		}
	}
	
	//个人PBC designed by:zhangsen 2018-03-08
	function jixiao_pbc_personal(){
		//指标类型筛选
		$this->assign('cids_list',$this->get_db_universal_type(17,NULL,NULL,1));
		$db_jixiao_pbc=M('db_jixiao_pbc');
		$db_jixiao_pbc_user=M('db_jixiao_pbc_user');
		$where['u_id']=$this->login_id;
		$where['type']=3;
		$result=$db_jixiao_pbc->where($where)->group('cid')->select();
		if(empty($result)){
			$user=$this->get_user($this->login_id);
			$where_p['p_id']=$user['position_id'];
			$where_p['type']=2;
			$result=$db_jixiao_pbc->where($where_p)->group('cid')->select();
			foreach($result as $key=>$value){
				$type_list=$this->get_db_universal_type(17,1,NULL,NULL,$value['cid']);
				$result[$key]['cname']=$type_list['name2'];	
				$where_d['cid']=$value['cid'];
				$where_d['p_id']=$user['position_id'];
				$where_d['type']=2;
				$result_d=$db_jixiao_pbc->where($where_d)->select();
				foreach($result_d as $kk=>$vv){
					$where_u['m_id']=$vv['id'];
					$where_u['status']=1;
					$result_u=$db_jixiao_pbc_user->where($where_u)->find();
					if($result_u){
						$result_d[$kk]['t1']=$result_u['t1'];
						$result_d[$kk]['t2']=$result_u['t2'];
						$result_d[$kk]['t3']=$result_u['t3'];
						$result_d[$kk]['c_value']=$result_u['c_value'];
						$result_d[$kk]['score']=$result_u['score'];
					}else{
						unset($result);
					}
				}
				if($result){
					$result[$key]['detail']=$result_d;
					$result[$key]['sum']=count($result_d);
				}
			}
		}else{
			foreach($result as $key=>$value){
				$type_list=$this->get_db_universal_type(17,1,NULL,NULL,$value['cid']);
				$result[$key]['cname']=$type_list['name2'];	
				$where_d['cid']=$value['cid'];
				$where_d['u_id']=$this->login_id;
				$where_d['type']=3;
				$result_d=$db_jixiao_pbc->where($where_d)->select();
				foreach($result_d as $kk=>$vv){
					$where_u['m_id']=$vv['id'];
					$where_u['status']=1;
					$result_u=$db_jixiao_pbc_user->where($where_u)->find();
					if($result_u){
						$result_d[$kk]['t1']=$result_u['t1'];
						$result_d[$kk]['t2']=$result_u['t2'];
						$result_d[$kk]['t3']=$result_u['t3'];
						$result_d[$kk]['c_value']=$result_u['c_value'];
						$result_d[$kk]['score']=$result_u['score'];
					}else{
						unset($result);
					}
				}
				if($result){
					$result[$key]['detail']=$result_d;
					$result[$key]['sum']=count($result_d);
				}
			}
		}
		$this->assign("result",$result);
		$this->display();
	}
}
?>